1

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

3 Answers 3

4

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
Sign up to request clarification or add additional context in comments.

Comments

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

Should do the trick.

answered Jun 30, 2010 at 15:38

1 Comment

It is also worth noting that the input class is automatically initialized so you do not have to load or autoload it.
0

Make sure the class input and post CodeIgniter there

if ($this->input->post())
Machavity
31.8k27 gold badges97 silver badges108 bronze badges
answered Jun 16, 2016 at 17:38

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.