Use data saved in a session

0

I modified my question because I was able to solve the session problem. But now I have another doubt. I have this code in the Controller to capture the data passed by parameter and save them in Session:

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

The url with the passing of the parameters that I'm using for testing is this: http://localhost/crm/trunk/click2call?color=4444&image=img.jpg .

So far so good. Now moving to the View. I made the following code to verify that the data was saved:

<?php $result = $this->session->userdata('click2call'); 
 foreach ($result as $row) {
 print_r($row);
 } ?>

And I had as a result: Array ( [image] => img.jpg [color] => 4444 ) . Right?

Now I want to know how I can use these values within View . For example, I have this default html:

<header data-color="<?php echo $client->click2call_color; ?>">

<h1>
    <?php if($client->click2call_image != ''): ?>
        <img src="<?php echo $client->click2call_image; ?>" alt="<?php echo $client->name; ?>"/>
    <?php else: ?>
        <?php echo lang('click2call_title'); ?></h1>
    <?php endif; ?>

Where, if these values are saved in the session: Color will replace header color - > <header data-color="<?php echo $client->click2call_color; ?>">

and image will replace the image - > img src="<?php echo $client->click2call_image; ?>" alt="<?php echo $client->name; ?>"/>

How can I do this check and assign these values?

    
asked by anonymous 25.03.2015 / 14:17

2 answers

2

Your session returns an array when you have multiple results: link

//view.php
<?php 
$sessao = $this->session-> userdata ('click2call'); 
if(!empty ($sessao){  
    echo "<header data-color=\"$sessao['client_id']['color']\">\n";
    echo "<img src=\"$sessão['client_id']['image']\" alt=\"$client->name\"/>\n";
}
else {
    echo "<header data-color=\"$client->click2call_color\">\n";
    echo "<img src=\"$client->click2call_image\" alt=\"$client->name\"/>\n";

}
    
25.03.2015 / 15:49
0

You can subscribe to the values like this:

$session = $this->session->userdata('click2call'); 
if($session != FALSE){
    if(isset($session['color'])) {
        $client->click2call_color = $session['color'];
    }
    if(isset($session['image'])) {
        $client->click2call_image = $session['image'];
    }
}
    
26.03.2015 / 13:57