nbwab
(Nicolas Bregenzer)
1
How do i correctly set the session lifetime or cookie parameters in general ??
$session = Yii::app()->session;
print_r($session->cookieParams);
$param = array();
$param["lifetime"] = 3600;
$session->setCookieParams($param);
print_r($session->cookieParams);
the second print_r works, the first, after reloading the page, not
kokomo
(Mwerlberger85)
2
The CHttpSession documentation says that the parameters you need have to set before the session is started.
In the How to implement session timeout? thread you can find examples how you can set session timeout.
For cookieParams it should be exactly the same.
nbwab
(Nicolas Bregenzer)
3
is the session already started after
$session = Yii::app()->session;
is called ?
Y11
(Y!!)
4
Yes, unless autostart is set to false.
But there’s no need to make things complicated, you can simply set this in config:
'components' => array(
...
'session' => array(
'cookieParams' => array(
'lifetime' => 300,
),
),
),
nbwab
(Nicolas Bregenzer)
5
if i try to set this property i get following error:
CWebApplication.session is read only.
455 }
456 }
457
458 /**
459 * Configures the module with the specified configuration.
460 * @param array $config the configuration array
461 */
462 public function configure($config)
463 {
464 if(is_array($config))
465 {
466 foreach($config as $key=>$value)
467 $this->$key=$value;
468 }
469 }
470
471 /**
472 * Loads static application components.
473 */
474 protected function preloadComponents()
475 {
476 foreach($this->preload as $id)
477 $this->getComponent($id);
478 }
479
mikl
(Mike)
6
Check your configuration array again. You probably haven’t put the ‘session’ section inside the ‘components’ array.