当你提交表单后,要显示信息提示用户时,就要用到setFlash,hasFlash,getFlash,在protected/controllers创建TestController.php文件,内容如下: ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| classTestControllerextendsCController
{
functionactionOk()
{
Yii::app()->user->setFlash('success','Everything went fine!');
$this->redirect('index');
}
functionactionBad()
{
Yii::app()->user->setFlash('error','Everything went wrong!');
$this->redirect('index');
}
functionactionIndex()
{
$this->render('index');
}
}
|
在protected/views/test创建index.php文件: ?
1
2
3
4
5
6
7
8
9
10
11
| user->hasFlash('success')):?>
user->getFlash('success')?>
user->hasFlash('error')):?>
user->getFlash('error')?>
|
|