How to check if a session exists (CodeIgniter)

2

I have the following function in my Controller :

private function SetImageAndColor($client_id) {
    if (isset($_GET['color']) AND isset($_GET['image'])) {
        $dados['click2call'][$client_id]['image'] = $this->input->get('image');
        $dados['click2call'][$client_id]['color'] = $this->input->get('color');
        $this->session->set_userdata('click2call', $dados);
    }
}

It takes the parameters passed via $_GET and saved in the session.

My question is this: how do I check if this session exists, but within View ?

    
asked by anonymous 20.03.2015 / 14:10

1 answer

4

You can check for values in the session:

Example:

// index_view.php
<html>
...
    <?php if($this->session->userdata('color') == 'blue') echo 'do_something'; ?>
...
</html>

However, I did not use this structure in IC to set values in the session: For your case, you would do the following, as found in the Codeigniter manual:

<?php 
    //controller.php    

    ...

    $image = $this->input->get('image');
    $color = $this->input->get('color');
    $this->session->set_userdata(array('nome' => 'click2call', 'id' => $cliente_id, 'image' => $image, 'color' => $color)); 
    
20.03.2015 / 20:01