views:

37

answers:

2

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() should 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; 
+2  A: 
$cuisineArr = ($this->input->post("cuisine") != false) : $this->input->post("cuisine") : array();

Should do the trick.

Nelson
It is also worth noting that the input class is automatically initialized so you do not have to load or autoload it.
evolve
+1  A: 

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; 
Jacob Relkin