Session Codeigniter

3

I have this normal session:

foreach ($nofeatured_prods as $k) {
    $_SESSION['itens'][$k->id] = $k;
}

How do I assign in the same way, however, in codeigniter?

    
asked by anonymous 08.12.2016 / 18:05

1 answer

3

Use the set_userdata () method of 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');

Upload

To load this library there are two ways, the first one is to call it just where it will be used or by demand and the second to let the framework already load it on all requests automatically.

First form:

$this->load->library('session');

Second form:

In the config / autoload.php file, look for $autoload['libraries'] and add in this array the session element.

$autoload['libraries'] = array('session', 'database');
    
08.12.2016 / 18:12