开发者

processing $_POST in codeigniter

开发者 https://www.devze.com 2023-01-05 18:51 出处:网络
How do i do this in codeigniter? $cuisineArr = isset($_POST[\'cuisine\']) ? $_POST[\'cuisine\'] : array();

How do i do this in codeigniter?

$cuisineArr = isset($_POST['cuisine']) ? $_POST['cuisine'] : array();

I read somewhere that using $_Post[''] direct is a not the right way and post() sho开发者_如何学编程uld be used instead. But how do i do the same in codeigniter?

I'm getting an array from a group of checkbox, then converting it to csv. The non-codeigniter code is below:

$cuisineArr = isset($_POST['cuisine']) ? $_POST['cuisine'] : array();
$cuisineArrCSV = implode(',',$cuisineArr);
echo $cuisineArrCSV; 


You need to use the CodeIgniter Input class.

Here's what your code should look like:

$cuisine = $this->input->post('cuisine');
$cuisineArr = ($cuisine != FALSE) ? $cuisine : array();
$cuisineArrCSV = implode(',',$cuisineArr);
echo $cuisineArrCSV; 


$cuisineArr = ($this->input->post("cuisine") != false) ? $this->input->post("cuisine") : array();

Should do the trick.


Make sure the class input and post CodeIgniter there

if ($this->input->post())
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号