Yii Framework Forum: CDbHttpSession and CController redirect() - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

CDbHttpSession and CController redirect() it not always writes data to the database when you call redirect() Rate Topic: -----

#1 User is offline   tybetx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-March 12

Posted 24 March 2012 - 05:17 AM

Hello,
I have a problem with CDbHttpSession, it not always writes data to the database when I call redirect()
If anyone knows this problem? This is strange behavior.
I have to directly call
Yii::app()->session->close();
before the
$this->redirect()
or
$this->refresh()
to the session data are stored.
Even
Yii::app()->onEndRequest = array(Yii::app()->session, 'close');
does not help...
I don't understand why.
When I use CHttpSession session data is saved correctly.
0

#2 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 478
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 26 March 2012 - 07:02 AM

Where are you setting
Yii::app()->onEndRequest = array(Yii::app()->session, 'close');
?
Make sure it is done after configuring Yii::app()->session and before the call to redirect().
You could put some debug output in CApplication::onEndRequest() to see if it is called.
Also check if your handler is listed in $this->getEventHandlers('onEndRequest');
0

#3 User is offline   tybetx 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 01-March 12

Posted 27 March 2012 - 05:02 PM

I added it to the Controller::init() and it was listed in Yii::app()->getEventHandlers('onEndRequest')
public function init() 
{
  parent::init();
  Yii::app()->onEndRequest = array(Yii::app()->session, 'close');
}

But it didn't work.
So I overwrote method Controller::redirect()
 public function redirect($url, $terminate=true, $statusCode=302)
{
  if (Yii::app()->session->useCustomStorage) {
    Yii::app()->session->close();
  }
  parent::redirect($url, $terminate, $statusCode);
}

and it's fine.
Look at http://code.google.c.../detail?id=2406

Sorry for my english.
0

#4 User is offline   CeBe 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 478
  • Joined: 16-July 10
  • Location:Berlin. Germany

Posted 27 March 2012 - 06:25 PM

If it is the only event handler in Yii::app()->getEventHandlers('onEndRequest') I don't see any reason, why it should not run...

btw: there is no problem with your english ;-)
0

#5 User is offline   rall0r 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 181
  • Joined: 11-November 10
  • Location:Bln

Posted 19 September 2012 - 08:12 AM

Hi,
strange thing... have exactly the same problem here: it looks like, new user session information/variables are lost after using redirect .. if they are stored in the same action before redirecting.
I'm searching my source code since hours without success and now I find this post which absolutely fits my problem.

I'm writing data to an user session variables using
Yii::app()->user->setState("solrSet","Content");

Followed by an redirect
$this->redirect(array('mycontroller/index','update'=>''));

In round about 1 of 5 cases the new stored session informations are lost.

This problem mostly exists by using CCacheHttpSession and CDbHttpSession.

Is it possible/planned to change the Yii-redirect-code, (for example) like tybetx wrote... in order to close the session before executing the redirect?!

Thank you, rall0r.

//Edit:
While investigating this problem and playing around with Yii::app()->session->close(); I found out, that not only redirect is the problem.
In my case also the following happend:
1.) the user submits an Form with ajaxSubmitButton
2.) the ajax action runs Yii::app()->user->setState() to set an session variable
3.) the ajax action ends with Yii::app()->end();
4.) the 'success' event from the ajaxSubmitButton starts and loads data from the server...
...and does not find the content from "2.)"
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users