CI增加类似ThinkPHP的success、error提示

CodeIgniter预定义全局success、error提示

首先找到CI的公共函数类/全局函数类文件:/system/core/Common.php
这里在该文件最底部添加如下代码:

  1. /** 
  2. * 成功跳转函数 
  3. * @access  public 
  4. * @param  mixed 
  5. * @return  mixed 
  6. */  
  7. if ( ! function_exists('success'))  
  8. {  
  9.   function success($tag,$url)  
  10.   {  
  11.     header("Content-type:text/html;charset=utf-8");  
  12.     echo '<script>alert("'.$tag.'");location.href="'.$url.'";</script>';  
  13.   }  
  14. }  
  15.   
  16. /** 
  17. * 错误跳转函数 
  18. * @access  public 
  19. * @param  mixed 
  20. * @return  mixed 
  21. */  
  22. if ( ! function_exists('error'))  
  23. {  
  24.   function error($tag)  
  25.   {  
  26.     header("Content-type:text/html;charset=utf-8");  
  27.     echo '<script>alert("'.$tag.'");window.history.back(-1);</script>';  
  28.   }  
  29. }  


使用示例:

  1. if($res){  
  2.   success('提交成功',site_url('welcome'));  //需要跳转的地址,例如跳转到welcome方法  
  3. }else{  
  4.   error('提交失败');  
  5. }  

本文最后更新于 2014-02-25 22:50:16 并被添加「codeigniter php框架 ci」标签,已有 14432 位童鞋阅读过。
本文作者:未来往事
本站使用「署名 4.0 国际」创作共享协议,可自由转载、引用,但需署名作者且注明文章出处

相关文章

此处评论已关闭