Codeigniter Session
I have this normal session:
foreach ($nofeatured_prods as $k) {
$_SESSION['itens'][$k->id] = $k;
}
How do I assign equally, though, in codeigniter?
3
1 answers
Use the method set_userdata() from the CI session Library
To assign do:
$var = array('nome' => 'teste');
$this->session->set_userdata($var);
Or:
$this->session->set_userdata('chave', 'valor');
To recover do:
$this->session->userdata('nome');
Loading
To load this library there are two ways, the first is to call it only where it will be used or by demand and the second let the framework already load it in all requests automatically.
First Form:
$this->load->library('session');
Second shape:
In the config/autoload file.php look for $autoload['libraries']
and add in this array the element session
.
$autoload['libraries'] = array('session', 'database');
4
Author: rray, 2016-12-09 17:46:33