Yii Framework Forum: How to Create Session && Reporting Error using session? - Yii Framework Forum

Jump to content

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

How to Create Session && Reporting Error using session? Rate Topic: -----

#1 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 11 February 2010 - 06:51 PM

I want to set new session for storing error notification.

I have trying to sett session using

Yii::app()->sesssion->add('error',CHtml::errorSummary($model));


this way is work, but I don't sure are this is the correct way for creating session?

so I wanna to get this session to displaying in form action

how to get session back?
and after error session displayed, I want to unset this session, where I can unset this session?

I wanna to using method = "post" in form without a duplicating possible entry if I refresh page after inserted.

thank you for your attention...
Thanks and Kind Regards
------
DanDinDun
0

#2 User is offline   Y!! 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 978
  • Joined: 18-June 09

Posted 11 February 2010 - 07:27 PM

For error notifications you can use CWebUser::setFlash().

For example you could do:

Yii::app()->user->setFlash('error', CHtml::errorSummary($model));


and then on the next user request you can test if the flash is set:

if (Yii::app()->user->hasFlash('error'))
{
   echo Yii::app()->user->getFlash('error');
}


A flash message is only available in the current and next user request (means you don't have to delete the flash after you displayed it).

Regarding sessions, should read this.
0

#3 User is offline   Dan Din Dun 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 77
  • Joined: 09-February 10

Posted 11 February 2010 - 08:20 PM

View PostY!!, on 11 February 2010 - 07:27 PM, said:

For error notifications you can use CWebUser::setFlash().

For example you could do:

Yii::app()->user->setFlash('error', CHtml::errorSummary($model));


and then on the next user request you can test if the flash is set:

if (Yii::app()->user->hasFlash('error'))
{
   echo Yii::app()->user->getFlash('error');
}


A flash message is only available in the current and next user request (means you don't have to delete the flash after you displayed it).

Regarding sessions, should read this.


oh.. great.. thank you sir. I will try to useing setFlas() and getFlash :-)
Thanks and Kind Regards
------
DanDinDun
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