Reputation: 2437
I want to send an array using a variable from view to controller, so that I can use it to get some data from database according to that array! For example, in my view I will have a variable with different equations like:
$data = 'setter';
and somewhere else:
$data = 'libero';
Then in my controller I will have a code like:
if($query = $this->players_model->get_players(array('player_Position' => $data, 'limit' => 3))) { $data['players'] = $query; }
what should I do to get it work?!
Upvotes: 2
Views: 6661
Reputation: 49817
first i would like to advise you , that whatever you are trying to achieve, the "pass an array from a view to a controller" is wrong , MVC pattern is not standing for passing data from view to a controller.
Then, i'l do like this:
//in view
$data = json_encode($myArray);
//in controller
$array = json_decode($data);
Upvotes: 3
Reputation: 6353
I would use session userdata
View
$data = array(
'setter' => 'value',
'libero' => 'value'
);
$this->session->set_userdata($data);
Controller
$setter = $this->session->userdata('setter');
$libero = $this->session->userdata('libero');
or
$data['setter'] = $this->session->userdata('setter');
$data['libero'] = $this->session->userdata('libero');
Upvotes: 1