Yii Framework Forum: Feedback messages to the user - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Feedback messages to the user Rate Topic: -----

#1 User is offline   jjmf 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 10-November 08

Posted 10 December 2008 - 05:13 PM

How are u guys doing with feedback messages to the user?
For example, after saving some info to the database, how are you doing to show an "Information saved successfully" message to the user?
Can you post some snipets?
0

#2 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 December 2008 - 05:41 PM

You may use the "flash" feature, like the following:

<?php
// controller part
public function actionUpdate()
{
if(model saved)
{
Yii::app()->user->setFlash('updateSuccess','data saved successfully');
$this->refresh();
}
$this->render('update');
}
?>


// view part
<?php if(Yii::app()->user->hasFlash('updateSuccess')): ?>
<?php echo Yii::app()->user->getFlash('updateSuccess'); ?>
<?php else: ?>
...show the form here...
<?php endif; ?>

0

#3 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 10 December 2008 - 05:43 PM

I think I would use a session variable.  Store the message in the session and then in the view (or even better the layout) check for the session variable, and if it exists, show it and than destroy it.
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,901
  • Joined: 04-October 08
  • Location:DC, USA

Posted 10 December 2008 - 05:47 PM

Yes, that's what "flash" does. The message will be discarded after it is displayed once. Therefore, if you refresh the page again, the message will disappear.
0

#5 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 10 December 2008 - 05:48 PM

Oh, so Yii does have flash methods... wasn't able to find any..
0

#6 User is offline   jjmf 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 10-November 08

Posted 11 December 2008 - 02:31 PM

Thank you folks!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

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