0
I modified my question because I was able to solve the problem of the session. But now I have another question. I have this code in 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 I’m using for testing is this:
http://localhost/crm/trunk/click2call?color=4444&image=img.jpg
.
So far, everything ok. Now going to the View. I made the following code to check if the data were saved:
<?php $result = $this->session->userdata('click2call');
foreach ($result as $row) {
print_r($row);
} ?>
And I got as a result:
Array ( [image] => img.jpg [color] => 4444 )
. Right?
Now I want to know how I can use these values within the 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 there are these values 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?
Solved it, thanks man!
– GWER
Or I could subscribe to the variable :
<?php 
$sessao = $this->session-> userdata ('click2call'); 
if(!empty ($sessao){ $client_click2call_color = $sessao['color'];
would be correct?– GWER
You can do that, yes!! I’m used to using the values right from the session, but it’s up to you (as long as it works rsrsrs)
– user21846
Dude, I’m having a little problem here. The first few times it worked perfectly. But now you’re no longer subscribing to the view values. What can it be?
– GWER
Got it, just needed to lock the color with
#
because the other was already coming from the database processed! Can you give me an idea? Instead ofif(!empty ($sessao)){
that checks if it is empty, would have to check if it is different from fake. How do I do? Thanks!– GWER
Also checking a php variable:
if(!$session)
,if($session != TRUE)
orif($session == FALSE)
– user21846
Thanks! And another, I can’t use the value directly. For example
$session = $this->session->userdata('click2call'); 
echo $session['color'];
I can only do a foreach, but I can’t use it...– GWER
And so:
echo $session->color;
??– user21846
Neither. And giving a print_r($Session) the result is simply Array.
– GWER