方法一:

<?php
Yii::app()->user->setFlash(‘success’,”Data saved!”); 设置键值名为success的临时信息.在getFlash后删除. 可以定义多种不同的键值名对象的消息.
?> <?php if(Yii::app()->user->hasFlash(‘success’)):?> 消息存在里,
<div>
<?php echo Yii::app()->user->getFlash(‘success’); ?> 输出消息内容,输出后,就不存在了.
</div>
<?php endif; ?> <?php //这是一段,在显示后定里消失的JQ代码,已集成至Yii中.
Yii::app()->clientScript->registerScript(
‘myHideEffect’,
‘$(“.info”).animate({opacity: 1.0}, 3000).fadeOut(“slow”);’,
CClientScript::POS_READY
);
?>

方法二:

http://www.yiiframework.com/forum/index.php/topic/22105-%E8%AF%B7%E9%97%AEyii%E9%87%8C%E9%9D%A2%E6%9C%89%E6%B2%A1%E6%9C%89%E6%98%BE%E7%A4%BA%E4%B8%B4%E6%97%B6%E6%B6%88%E6%81%AF%EF%BC%8C%E5%87%A0%E7%A7%92%E5%90%8E%E8%B7%B3%E8%BD%AC%E7%9A%84%E5%8A%9F%E8%83%BD%E5%95%8A%EF%BC%9F/

1,在CWebUser扩展类中

        publicfunction pushMessage($string=null, $type='successMsg')
{
if($string!=null){
if($this->hasFlash($type))
$old = $this->getFlash($type);
else
$old = array();
array_push($old, $string);
$this->setFlash($type, $old);
}
}
publicfunction showPutMsg()
{
$show ='';
$successName='successMsg';
$noticeName='noticeMsg';
$errorName='errorMsg'; if($this->hasFlash($successName)){
$show.='<div class="flash-success">';
$msg=(array) $this->getFlash($successName);
$show.='<ul>';
for($i=0; $i<count($msg); $i++){
$show.='<li>'. $msg[$i].'</li>';
}
$show.='</ul></div>';
}
if($this->hasFlash($noticeName)){
$show.='<div class="flash-notice">';
$msg=(array) $this->getFlash($noticeName);
$show.='<ul>';
for($i=0; $i<count($msg); $i++){
$show.='<li>'. $msg[$i].'</li>';
}
$show.='</div>';
}
if($this->hasFlash($errorName)){
$show.='<div class="flash-error">';
$msg=(array) $this->getFlash($errorName);
$show.='<ul>';
for($i=0; $i<count($msg); $i++){
$show.='<li>'. $msg[$i].'</li>';
}
$show.='</div>';
}
return $show;
} publicfunction putSuccessMsg($string=null)
{
$this->pushMessage($string,'successMsg');
}
publicfunction putNoticeMsg($string=null)
{
$this->pushMessage($string,'noticeMsg');
}
publicfunction putErrorMsg($string=null)
{
$this->pushMessage($string,'errorMsg');
}

2,在controller中,可以有三种提示信息

Yii::app()->user->putSuccessMsg('操作成功啦!');
Yii::app()->user->putNoticeMsg('操作警告...');
Yii::app()->user->putErrorMsg('操作失败了!');

3,最后在view中统一弹出便可。

<?php echo Yii::app()->admin->showPutMsg();?>

一般不要采用js弹窗形式,用户体验不是很好。

方法三:

public function redirect_message($message='成功', $status='success',$time=3, $url=false )
{ $back_color ='#ff0000'; if($status =='success')
{
$back_color= 'blue';
} if(is_array($url))
{
$route=isset($url[0]) ? $url[0] : '';
$url=$this->createUrl($route,array_splice($url,1));
}
if ($url)
{
$url = "window.location.href='{$url}'";
}
else
{
$url = "history.back();";
}
echo <<<HTML
<div>
<div style="background:#C9F1FF; margin:0 auto; height:100px; width:600px; text-align:center;">
<div style="margin-top:50px;">
<h5 style="color:{$back_color};font-size:14px; padding-top:20px;" >{$message}</h5>
页面正在跳转请等待<span id="sec" style="color:blue;">{$time}</span>秒
</div>
</div>
</div>
<script type="text/javascript">
function run(){
var s = document.getElementById("sec");
if(s.innerHTML == 0){
{$url}
return false;
}
s.innerHTML = s.innerHTML * 1 - 1;
}
window.setInterval("run();", 1000);
</script>
HTML;
}

把代码拷入 CController.php 文件下

方法四:
http://www.yiiframework.com/forum/index.php?/topic/8949-%E8%80%81%E5%A4%A7%EF%BC%8Cyii%E6%9C%89%E6%B2%A1%E6%9C%89%E8%B1%A1qeephp%E4%B8%AD%E7%9A%84-redirectmessage%E4%BF%A1%E6%81%AF%E6%8F%90%E7%A4%BA%E5%87%BD%E6%95%B0/page__p__44880
publicfunction redirectMessage($message, $url, $delay=5, $script='')
{
$this->layout=false;
if(is_array($url))
{
$route=isset($url[0])? $url[0]:'';
$url=$this->createUrl($route,array_splice($url,1));
}
return $this->render('/redirect', array(
'message'=> $message,
'url'=> $url,
'delay'=> $delay,
'script'=> $script,
));
}
把这个方法放到CBaseController中(也就是你的父控制器中,这样,所有的控制器都以调用了, 就相当于全局函数了)

From: http://www.cnblogs.com/Alight/archive/2013/01/18/2866421.html

yii 中设置提示成功信息,错误提示信息,警告信息的更多相关文章

  1. yii中设置提示成功信息,错误提示信息,警告信息

    方法一: <?phpYii::app()->user->setFlash(‘success’,”Data saved!”); 设置键值名为success的临时信息.在getFlash ...

  2. Jquery插件之信息弹出框showInfoDialog(成功、错误、警告、通知)

    一.信息种类说明: 1.1.操作成功信息 1.2.错误信息 1.3.警告信息 1.4.通知信息 二.使用说明 <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...

  3. 在Xcode中如何屏蔽某个源文件的编译警告信息

    某些时候如果我们的源码在编译过程中出现大量的编译警告时,看起来是挺不爽的:但又确实没办法解决警告问题的时候,我们可以使用下面的方法来屏蔽指定的某个文件的所有警告信息. 1.在Xcode中选中工程文件. ...

  4. Yii中设置时间分区

    在wamp环境下,运行一个Php yii的项目 出现问题: Use of undefined constant PRC - assumed 'PRC' 检测我的环境 PHP5.3 检测Php.ini中 ...

  5. Android Studio中设置提示函数用法

    Eclipse有一个很好的功能,就是当你代码调用某个android API时,鼠标移到对应的函数或者方法上,就会自动有一个悬浮窗提示该函数的说明(所包含的参数含义,该方法功能).迁移到Android ...

  6. 在makefile中打印错误或警告信息

    在makefile中打印警告或者错误消息的方法: $(warning xxxxx) 或者 $(error xxxxx) 输出变量方式为: $(warning $(XXX))

  7. odoo开发笔记 -- 异常、错误、警告、提示、确认信息显示

    1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息: raise osv.except_osv(_('Error!'), _('Error Message.')) 示例代码: #删除当前销售单 ...

  8. openerp学习笔记 错误、警告、提示、确认信息显示

    1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息: raise osv.except_osv(_('Error!'), _('Error Message.')) 示例代码: #删除当前销售单 ...

  9. make only output error/warning message( 编译时,只输出错误信息和警告信息)

    make > /dev/null 这样,正常的信息被重定向输出到/dev/null,错误和警告信息会输出到标准错误设备(standard error,相对于标准输入/输出设备来说).

随机推荐

  1. 思维导图软件VYM

    http://www.insilmaril.de/vym/ 点击打开链接http://www.oschina.net/p/vym 有人说VYM就跟目录是一回事,确实是这样, 只不过与excel之类的比 ...

  2. mysql 查找包含特定名字的表

    SELECT distinct TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME LIKE '%medias%'

  3. 新开窗口不被拦截的方法-window.open和表单提交form

    $("#btn").click(function() { var w = window.open(); setTimeout(function() { w.location = & ...

  4. PDO操作mysql数据库(一)

    PHP连接mysql数据库: <?php$server = "localhost";$user = "root";$pwd = "123456& ...

  5. css 浮动 相对定位 绝对定位区别

    今天下班在地铁上看了一个样式教学视频,因为最近在学习前端.以前刚毕业的时候,感觉后台才是王道,但最近发现,前端也很重要,比如:自己接一些私单做的时候,自己要根据需求做好界面,才能更加符合客户需求,不然 ...

  6. angular分页指令

    目前的多个项目中都用到分页这个功能,为了提高可复用性,我特地分离出来写了个分页的指令.直接贴代码,详情如下: index.html <body id="sBill" ng-c ...

  7. uva_1422 Processor

    题目链接 题意: 有n个任务, 每个任务要在规定的时间[l, r]内完成, 工作量为 w, 每个任务可以分开完成. 求, 使得所有任务都完成的最大速度的最小值. 思路: 最大值最小问题, 二分. 因为 ...

  8. IronPython 源码剖析系列(2):IronPython 引擎的运作流程

    http://blog.csdn.net/inelm/article/details/4612987 一.入口点 Python 程序的执行是从 hosting 程序 ipy.exe 开始的,而他的入口 ...

  9. 【HDOJ】3560 Graph’s Cycle Component

    并查集的路径压缩. #include <stdio.h> #include <string.h> #define MAXNUM 100005 int deg[MAXNUM], ...

  10. Unreachable catch block for IOException. This exception is never thrown from the try statement body

    Unreachable catch block for IOException. This exception is never thrown from the try statement body ...