How to use cookie in Zend Framework 2? [closed]
Asked Answered
K

1

1

I cant understand how to use cookies in ZF2? Can some one advise some links with set and get cookie?

Kizer answered 3/10, 2012 at 11:27 Comment(4)
de.php.net/manual/de/features.cookies.php Nothing Zend Specific here... Going with how many entry level questions you got, you might be advised to learn basic OOP PHP5 programming - outside of ZF :SRectocele
i know how to use cookie outside ZF, but how it works in Zf2?Kizer
so i find out how it works how to close a question?Kizer
You should write down how it works as an answer, for other people who may look for the same problemRectocele
E
3

simply use the rememberMe() method on the SessionManager to set a cookie

See SessionManager Code on line 260

there also is forgetMe() to remove the cookie

additionally you can configure the defaults for your session manager like this:

Module.php

public function onBootstrap(\Zend\EventManager\EventInterface $e)

    $config = $e->getApplication()
        ->getServiceManager();
        ->get('Configuration');

    $sessionConfig = new SessionConfig();
    $sessionConfig->setOptions($config['session']);
    $sessionManager = new SessionManager($sessionConfig, null, null);
    Session::setDefaultManager($sessionManager);
}

module.config.php

return array(
    'session' => array(
        'remember_me_seconds' => 2419200,
        'use_cookies' => true,
        'cookie_httponly' => true,
    ),
);

See this class for a complete list of configuration options:

Eucharist answered 3/10, 2012 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.