[eluser]vecima[/eluser]
First of all, hello. I've been messing around with CI for a few weeks, checking out the user's guide, and lurking at these forums, and I've been able to get a good amount accomplished. I'm doing a full rewrite of my site on CI and so far am amazed by how everything works.
I have hit a stumbling block though with regards to the cookie helper... I did search these forums but I couldn't find what I was looking for. My problem seems to be that cookies aren't being sent. I'm writing my own style switcher (I know it's been done, but I'm doing it for practice, and to avoid using javascript). So, in the footer that is always shown on my site, i have the following:
Code:
<a href="<?=base_url()?>style/change/standard/<?=$uri_1?>/<?=$uri_2?>/<?=$uri_3?>/<?=$uri_4?>">standard</a> |
<a href="<?=base_url()?>style/change/greyscale/<?=$uri_1?>/<?=$uri_2?>/<?=$uri_3?>/<?=$uri_4?>">greyscale</a> |
<a href="<?=base_url()?>style/change/inverted/<?=$uri_1?>/<?=$uri_2?>/<?=$uri_3?>/<?=$uri_4?>">inverted</a> |
<a href="<?=base_url()?>style/change/sobel/<?=$uri_1?>/<?=$uri_2?>/<?=$uri_3?>/<?=$uri_4?>">sobel</a> |
<a href="<?=base_url()?>style/change/irradiated/<?=$uri_1?>/<?=$uri_2?>/<?=$uri_3?>/<?=$uri_4?>">irradiated</a>
In my style controller, there is only the function "change" in which I set a cookie to determine the style, then redirect back to where the user came from.
my "Style" controller:
Code:
function change($newStyle='standard', $controller=NULL, $function=NULL, $arg1=NULL, $arg2=NULL)
{
$back_to = array();
if ($controller != NULL) {
$back_to[0] = $controller;
}
if ($function != NULL) {
$back_to[1] = $function;
}
if ($arg1 != NULL) {
$back_to[2] = $arg1;
}
if ($arg2 != NULL) {
$back_to[3] = $arg2;
}
$style_cookie = array(
'name' => 'MyPreferredStyle',
'value' => $newStyle,
'expire' => '31556926',
'domain' => '.mydomain.com',
'path' => '/',
'prefix' => '',
);
set_cookie($style_cookie);
$this->data['newStyle'] = $newStyle;
redirect("/$back_to[0]/$back_to[1]/$back_to[2]/$back_to[3]", 'location');
}
and this is one of my controller's render function. I'm trying to pick the cookie back up and take the value out of it to set the style.
Code:
function render($view='welcome')
{
$this->data['uri_1'] = $this->uri->segment(1);
$this->data['uri_2'] = $this->uri->segment(2);
$this->data['uri_3'] = $this->uri->segment(3);
$this->data['uri_4'] = $this->uri->segment(4);
$this->load->helper('cookie');
if($styled = get_cookie('MyPreferredStyle')) {
$this->data['newStyle'] = $styled['value'];
} else {
$this->data['newStyle'] = 'standard';
}
$content = $this->load->view($view, $this->data, true);
$output = $this->load->view('header', $this->data, true);
$output .= $this->load->view('nav', $this->data, true);
$output .= $content;
$output .= $this->load->view('footer', $this->data, true);
$this->output->set_output($output);
}
one thought I had was: could the cookie not get set due to this running on "localhost" rather than "mydomain.com"... that is, could the browser not accept cookies with differing domains?
a preemptive thanks for the help!