A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

当你提交表单后,要显示信息提示用户时,就要用到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')?>



1 个回复

倒序浏览
奈斯,感谢分享
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马