After redirect from a controller Yii session not working

After save a model i want to store a model auto increment id in a session variable and redirect to a view page. When i want to echo that session variable in view page it is not working.

Note: I don't use user login/logout system.

In config.php

'session' => array(
        'autoStart'=>true,
        'timeout'=>1200,
    ),

In Controller File

if ($model->save()) {
    Yii::app()->session['orderId']=$model->id;
    $this->redirect(array('view', 'id' => $model->id));
}

In the controller where i use redirect() if i use render() then it's work. After redirect it's not working.

In View File

echo Yii::app()->session['orderId'];

Please Help Me :(

You can store session data with

if ($model->save()) {
Yii::app()->user->setState('orderId', $model->id);
}

Get it with

echo Yii::app()->user->getState('orderId');

Both configs, models and controllers are set up the same for them. But property does not work after redirect. But with property session is destroyed  After the session expiry, it does not redirect to the login screen. Controller (it should not match to guests, according to the documentation): class Defaul Hello, I just updated to 2.0.7, and it seems something wrong with user handling.

Try this ,

in your controller

if ($model->save()) {
    Yii::app()->user->setState("orderId",$model->id);
     $this->redirect(array('view', 'id' => $model->id));

}

//get session variable

Yii::app()->user->getState("orderId");

I have this in my base controller to set user session timeout: actually on the home page while timeout occurres, the flash message on the home page is not visible after redirect. Any idea why this does not work as expected? And after redirect url is 0.0.0.0/controller/action php/controller/action localhost/controller/action into access log's files? This comment has been minimized. Sign in to view

Try to add "return" before redirect:

return $this->redirect(array('view', 'id' => $model->id);

I am trying to set session in yii 1.1 But we can not get any success. Could you exit; //Redirect URL } While hit my getSession after setSession only blank white page coming. Is routing the only way of passing data to the controller in ZF2? samdark changed the title Controller::redictect() does not work from ErrorHandler::errorAction Controller::redirect() does not work from ErrorHandler::errorAction Mar 10, 2016 samdark closed this Mar 10, 2016

GitHub is home to over 50 million developers working together to { $messages = \Yii::$app->session->getFlash('app-flash-message'); if(! of beforeAction is like it's done in yii\web\Controller so your code with this Every time after successful form submission, call redirect() to prevent resubmission of form. Hi, I'm working of educational website and I'm using the great yii2-user Let say when user on course/show action, he choose to login using the navbar link to login. after click on the link, he will go to site/login to see the login form

in SiteController::actionLogin(), i have modified the code from: yii2 losing user identity after login redirect, Same problem, after 3 days find I made sure that session was enabled and enableAutologin was also true, but I had no luck at all. If you haven't explicitly configured the session, it's fine. Then the problem does not exists in the storage but somewhere else in login process. This comment has been minimized.

Get code examples like "php session empty after redirect" instantly right Dynamic Carousel in Laravel not working displays only one image  yii\redis\Session: stores session data using redis as the storage medium. yii\mongodb\Session: stores session data in a MongoDB. All these session classes support the same set of API methods. As a result, you can switch to a different session storage class without the need to modify your application code that uses sessions.

Comments
  • Thanks for your reply. But it's not work. Are you sure your code will work for guest user? Because i mentioned my question "Note: I don't use user login/logout system."