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;
asked Jun 30, 2010 at 15:33
esafwan
18.2k35 gold badges111 silver badges170 bronze badges
3 Answers 3
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;
answered Jun 30, 2010 at 15:39
Jacob Relkin
164k34 gold badges352 silver badges321 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
$cuisineArr = ($this->input->post("cuisine") != false) ? $this->input->post("cuisine") : array();
Should do the trick.
answered Jun 30, 2010 at 15:38
Nelson
1,7573 gold badges16 silver badges26 bronze badges
1 Comment
tplaner
It is also worth noting that the input class is automatically initialized so you do not have to load or autoload it.
Make sure the class input and post CodeIgniter there
if ($this->input->post())
Comments
lang-php