方法一:

<?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. android程序的安装与卸载

    Android android在安装应用程序与卸载应用程序时都会发送广播,安装应用程序成功时会发送android.intent.action.PACKAGE_ADDED广播,可以通过intent.ge ...

  2. 搭建LNMP发布ecshop系统及压测启用opcache缓存与否的情况

    安装环境:CENTOS6.5,nginx1.6.2,php-5.5.18,mysql5.5.38 在安装软件之前安装epel源,就可以直接用yum安装libmcrypt,mhash,mcrypt等ph ...

  3. 以查询方式实现1s定时

    以查询控制器的控制位状态来实现1s定时. #include <reg52.h> sbit LED = P0^; unsigned ; void main () { LED = ; // 点 ...

  4. 大话设计模式(带目录完整版).pdf等

    点击进入百度网盘 大话设计模式(带目录完整版).pdf等 保存至网盘下载二维码举报 赞(0)| 评论 | 分享至 分享时间:2014-04-01 11:02 | 467次浏览 130次下载 81次保存 ...

  5. 对ARM9哈佛结构的认识

    书本上都说ARM是哈佛结构,但是我总感觉好像看不出来.后来针对S3C2440的ARM9核进行分析,我有了自己的见解. 我的结论是“ARM9被称为是哈佛结构是从它拥有指令cache和数据cache”来说 ...

  6. MIME

    http://www1.huachu.com.cn/read/readbookinfo.asp?sectionid=1000000558 http://www.jb51.net/hack/10623. ...

  7. 配置Tomcat JNDI数据源

    原文地址:http://my.oschina.net/xiaomaoandhong/blog/74584 先记录在此,按照博文未配置成功

  8. Cxf + Spring3.0 入门开发WebService

    转自原文地址:http://sunny.blog.51cto.com/182601/625540/ 由于公司业务需求, 需要使用WebService技术对外提供服务,以前没有做过类似的项目,在网上搜寻 ...

  9. [收藏转贴]构建RESTful风格的WCF服务

    RESTful Wcf是一种基于Http协议的服务架构风格. 相较 WCF.WebService 使用 SOAP.WSDL.WS-* 而言,几乎所有的语言和网络平台都支持 HTTP 请求. RESTf ...

  10. Android开源项目发现---Menu 篇(持续更新)

    1. MenuDrawer 滑出式菜单,通过拖动屏幕边缘滑出菜单,支持屏幕上下左右划出,支持当前View处于上下层,支持Windows边缘.ListView边缘.ViewPager变化划出菜单等. 项 ...