Cookies

What is the correct way to set cookies from controller?

looking at the source code ,it must be something like this, but won't work.

$cook = new \Phalcon\Http\Response\Cookies();
$cook->setDI($this->getDI());
$cook->set('testook', 'testvalue', time()+60*60*24, '/');

and going through the whole source from $app->handle(), at the end there is call ```sh PHALCONCALLMETHODNORETURN(response, "sendheaders"); ``` and $response->sendHeaders() call's send() only if $response->headers != null

and then in $response->send() ```sh PHALCONOBSVAR(cookies); phalconreadproperty(&cookies, thisptr, SL("cookies"), PHNOISYCC); if (ZTYPEP(cookies) != ISNULL) { PHALCONCALLMETHODNORETURN(cookies, "send"); } ``` so $response->cookies is internally set from $cook->set(...) call, BUT ```sh PHALCONCALLMETHODNORETURN(cookies, "send"); ```

There is no send method in \Phalcon\Http\Response\Cookies :/ I've missed something?



84.4k

Response\Cookies component still need some more work, it's simpler use the set_cookie function provided by PHP:

setcookie('testook', 'testvalue', time()+60*60*24, '/');


84.4k

The cookies component is now ready to use in 1.1.0



11.4k
edited Jul '14

@phalcon I'm using 1.2.0 and cookies expire time just don't get set:

$this->cookies->set('sample_cookie', 'sample_value', time() + 86400 * 7);

sets a session cookie.

However if I'm using:

setcookie('sample_cookie', 'sample_value', time() + 86400 * 7);

it works fine.

Tried Vokuro app and this issue persists there.