saegeek
(Abdallah)
May 28, 2012, 9:40am
1
Hi,
I’m trying to show a flash message as a result of a just sent form.
The code i used is the same as the one at contact-page except my form header:
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'feedbacks-form',
'enableAjaxValidation'=>false,
'action'=>'products/details',
)); ?>
I think my browser (Firefox 12) loads the “resulting page” from cache because when i set a new session var that i increment at each page visit, the counter doesn’t refresh :
<?php if (Yii::app()->user->getState('foo')===NULL) {
Yii::app()->user->setState('foo',1);
} else {
$x=Yii::app()->user->getState('foo');
Yii::app()->user->setState('foo',++$x);
}
print_r(Yii::app()->user->getState('foo'));?>
The only way to show the flash message is:
<?php if (Yii::app()->user->hasFlash('feedback')):?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('feedback');?>
</div>
<?php exit;endif;?>
But “exit” is not a solution
joblo
(Joe)
May 28, 2012, 10:49am
2
Maybe this extension helps.
saegeek
(Abdallah)
May 28, 2012, 11:19am
3
I would like to reproduce the same scenario as contact page.
Don’t need of more effects.
On the contact page the session counter i made increments perfectly (+1) :
<?php if (Yii::app()->user->getState('foo')===NULL) {
Yii::app()->user->setState('foo',1);
} else {
$x=Yii::app()->user->getState('foo');
Yii::app()->user->setState('foo',++$x);
}
print_r(Yii::app()->user->getState('foo'));?>
but at my web page i just get the non-incremented value, maybe browser-cache ?
when i disable browser cache using cache toggle
it increments by +2 at the returned page (page with getflash())
saegeek
(Abdallah)
May 28, 2012, 11:53am
4
I just noticed that it works well on opera.
I wonder what is the difference between my form and the one @ contact page…
jayant
(Codesutras)
May 28, 2012, 11:57am
5
lets try to add
'autoUpdateFlash' => false,
in component array of config.
Seal
(Sealtrip)
May 28, 2012, 4:56pm
6
Have you tried
Yii::app()->user->setFlash('flashMessageId', 'Your Message');
from your controller?
saegeek
(Abdallah)
May 28, 2012, 6:59pm
7
Problem is semi-solved
I downgraded firefox from v12 to v11 and it worked one shot !
In v12 the returned page is loaded from cache and when i disable browser cache, Firefox asks for the page one-more time and because of this behavior the flash message is removed. When i exit() after getFlash() i can see the flash message.
my controller :
public function actionDetails($id) {
$this->loadModel($id);
$feedbacks=new Feedbacks;
if (isset($_POST['Feedbacks'])) {
$feedbacks->attributes=$_POST['Feedbacks'];
...
...
if ($feedbacks->save()) {
...
...
Yii::app()->mailer->Send();
Yii::app()->user->setFlash('feedback','Your feedback was received, it will be shown once it is approved.');
$this->refresh();
}
$this->render('details',array(
...
my view:
<?php
$this->widget('CTabView',array(
'cssFile'=>'/css/tabs.css',
'activeTab'=>(Yii::app()->request->isPostRequest?'tab2':'tab1'),
'tabs'=>array(
'tab1'=>array(
'title'=>'View feedbacks',
'view'=>'feedbacks/_list',
'data'=>array(
'dataProvider'=>$dataProvider,
'product_id'=>$product_id,
),
),
'tab2'=>array(
'title'=>'Post a feedback',
'view'=>'feedbacks/_form',
'data'=>array(
'feedbacks'=>$feedbacks,
),
),
)));
_list tab:
<?php if (Yii::app()->user->hasFlash('feedback')):?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash('feedback');?>
</div>
<?php endif;?>
jzhong5
(Jzhong5)
May 30, 2012, 10:37am
8
saegeek:
Problem is semi-solved
'autoUpdateFlash' => false,
Add this line, your problem will be solved in just 1 second.
saegeek
(Abdallah)
May 30, 2012, 12:04pm
9
I already tried that and it doesn’t solves anything.
The problem appears only on Firefox from version 12
saegeek
(Abdallah)
May 30, 2012, 3:18pm
10
Many other Firefox12 users experienced this problem:
http://support.mozilla.org/fr/questions/926043