yii 中设置提示成功信息,错误提示信息,警告信息
方法一:
<?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 文件下
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 中设置提示成功信息,错误提示信息,警告信息的更多相关文章
- yii中设置提示成功信息,错误提示信息,警告信息
方法一: <?phpYii::app()->user->setFlash(‘success’,”Data saved!”); 设置键值名为success的临时信息.在getFlash ...
- Jquery插件之信息弹出框showInfoDialog(成功、错误、警告、通知)
一.信息种类说明: 1.1.操作成功信息 1.2.错误信息 1.3.警告信息 1.4.通知信息 二.使用说明 <!DOCTYPE html PUBLIC "-//W3C//DTD HT ...
- 在Xcode中如何屏蔽某个源文件的编译警告信息
某些时候如果我们的源码在编译过程中出现大量的编译警告时,看起来是挺不爽的:但又确实没办法解决警告问题的时候,我们可以使用下面的方法来屏蔽指定的某个文件的所有警告信息. 1.在Xcode中选中工程文件. ...
- Yii中设置时间分区
在wamp环境下,运行一个Php yii的项目 出现问题: Use of undefined constant PRC - assumed 'PRC' 检测我的环境 PHP5.3 检测Php.ini中 ...
- Android Studio中设置提示函数用法
Eclipse有一个很好的功能,就是当你代码调用某个android API时,鼠标移到对应的函数或者方法上,就会自动有一个悬浮窗提示该函数的说明(所包含的参数含义,该方法功能).迁移到Android ...
- 在makefile中打印错误或警告信息
在makefile中打印警告或者错误消息的方法: $(warning xxxxx) 或者 $(error xxxxx) 输出变量方式为: $(warning $(XXX))
- odoo开发笔记 -- 异常、错误、警告、提示、确认信息显示
1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息: raise osv.except_osv(_('Error!'), _('Error Message.')) 示例代码: #删除当前销售单 ...
- openerp学习笔记 错误、警告、提示、确认信息显示
1.检查业务逻辑中的错误,终止代码执行,显示错误或警告信息: raise osv.except_osv(_('Error!'), _('Error Message.')) 示例代码: #删除当前销售单 ...
- make only output error/warning message( 编译时,只输出错误信息和警告信息)
make > /dev/null 这样,正常的信息被重定向输出到/dev/null,错误和警告信息会输出到标准错误设备(standard error,相对于标准输入/输出设备来说).
随机推荐
- JS将时间戳转换为JS Date类型
/*将JSON Date 格式转换为JavaScript 的Date 类型JSON Date 格式:"/Date(146471041000)/"*/function JSONDat ...
- php url字符转义操作
遇到一段代码,从数据库里读出来带 \ 字符 需要转义成中文~ 用到url_decode(); //$info 为刚从数据库中读取的二维数组 foreach($info as $key1 => & ...
- #Leet Code# Sqrt
描述:log(n) 代码: class Solution: # @param x, an integer # @return an integer def getVal(self, begin, en ...
- HTML5:一个拖拽网页元素的例子
关键字:HTML5, Drag&Drop, JavaScript, CSS 运行环境:Chrome <!DOCTYPE html> <html> <head> ...
- skip index scan
官网对skip index scan的解释: Index skip scans improve index scans by nonprefix columns since it is often f ...
- cocos2d-x笔记4: TextField不能删除内容,以及我的解决办法。。。
3.0正式版,win32下,TextField按下backspace键不能删除内容.网上搜了下,很早就有的问题了,正式版了竟然还不解决... 真心无力吐槽啊!!!这种巨大而又明显的Bug... 从昨天 ...
- 【原创】Mvc学习笔记(1)
1.新建MVC4项目 在MVC4中有App_Data文件夹,这个文件夹里可以放一些重要的数据,比如说数据库的mdf文件等等,这个文件夹非常安全,因为这个文件夹不允许被别人下载,不允许被浏览器访问. A ...
- tableView被Nav挡住了
// 1. // self.navigationController.navigationBar.translucent = NO; // self.tabBarController.ta ...
- python下redis的基本操作:
1. 基本操作: >>> import redis >>> print redis.__file__ /usr/local/lib/python2.7/dist-p ...
- Android使用pull解析xml
一.理论准备 Pull解析器的运行方式与 SAX 解析器相似.它提供了类似的事件,如:开始元素和结束元素事件,使用parser.next()可以进入下一个元素并触发相应事件.跟SAX不同的是, ...