博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Zend Framework相关
阅读量:5260 次
发布时间:2019-06-14

本文共 3012 字,大约阅读时间需要 10 分钟。

不使用view

1$this->_helper->viewRenderer->setNoRender();

Ajax相关

1 class AjaxRes  2 { 3     const STATUS_SUCCESS = 0; 4     const STATUS_ERROR = 1; 5     private $_arrRes; 6     function __construct(){ 7         $this->_arrRes = array('status'=>self::STATUS_SUCCESS,'statusinfo'=>'操作成功'); 8     } 9     public function toJson(){10         return json_encode($this->_arrRes);11     }12     public function setStatusError(){13         $this->_arrRes['status'] = self::STATUS_ERROR;14     }15     public function setStatusSuccess(){16         $this->_arrRes['status'] = self::STATUS_SUCCESS;17     }18     public function setStatusInfo($strStatusInfo){19         $this->_arrRes['statusinfo'] = $strStatusInfo;20     }21     public function set($key, $val){22         $this->_arrRes[$key] = $val;23     }24 }
1  public function init() 2     { 3         $this->initView(); 4         $this->view->baseUrl = $this->_request->getModuleName(); 5         $this->view->baseController = $this->_request->getControllerName(); 6     } 7     /** 8      * 校验参数 9      * @throws Exception_CanBeShow10      */11     abstract protected function _checkParams();12 13     14     protected function _noLayout() {15         $this->_helper->layout()->disableLayout();16     }17     18     protected function _noViewScript() {19         $this->_helper->viewRenderer->setNoRender();20     }21     22     protected function _changeLayout($newLayout) {23         $this->_helper->layout()->setLayout($newLayout);24     }25     26     protected function _changeView($viewScript) {27         $this->view->render($viewScript);28     }29     30     protected function _sendJsonHeader() {31         $this->_noLayout();32         $this->_noViewScript();33         header('Content-type: text/json; charset=utf-8');34     }35     36     protected function _sendDownloadHeader($strFileName) {37         $this->_noLayout();38         $this->_noViewScript();39         header('Content-Type: application/octet-stream');40         Header("Accept-Ranges: bytes"); 41         Header("Accept-Length: ".filesize($strFileName)); 42         $encoded_filename = urlencode($strFileName);43         $encoded_filename = str_replace("+", "%20",$strFileName);44         if (preg_match("/MSIE/", $_SERVER['HTTP_USER_AGENT'])) 45         { 46             header('Content-Disposition: attachment;filename="' . $encoded_filename . '"');47         }48         else if (preg_match("/Firefox/", $_SERVER['HTTP_USER_AGENT']))49         { 50             header('Content-Disposition: attachment; filename*="utf8\'\'' . $strFileName . '"');51         } else { 52             header('Content-Disposition: attachment; filename="' . $strFileName . '"');53         }54     }

使用方法:

1 $ajaxRes = new StoneSun_AjaxRes();2 $this->_sendJsonHeader();3 $ajaxRes->setStatusError();4 $ajaxRes->setStatusInfo("验证码不正确");5 echo $ajaxRes->toJson(); die();6 $ajaxRes->setStatusInfo('注册成功');7 echo $ajaxRes->toJson(); die();

 

转载于:https://www.cnblogs.com/jishuixiansheng/archive/2012/06/12/2546959.html

你可能感兴趣的文章
Hibernate-缓存
查看>>
【BZOJ4516】生成魔咒(后缀自动机)
查看>>
提高PHP性能的10条建议
查看>>
svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法...
查看>>
Java大数——a^b + b^a
查看>>
【动态规划】skiing
查看>>
java定时器的使用(Timer)
查看>>
boost 同步定时器
查看>>
[ROS] Chinese MOOC || Chapter-4.4 Action
查看>>
简单的数据库操作
查看>>
Redmine
查看>>
帧的最小长度 CSMA/CD
查看>>
编程算法 - 左旋转字符串 代码(C)
查看>>
IOS解析XML
查看>>
Python3多线程爬取meizitu的图片
查看>>
树状数组及其他特别简单的扩展
查看>>
110104_LC-Display(液晶显示屏)
查看>>
php学习笔记
查看>>
普通求素数和线性筛素数
查看>>
PHP截取中英文混合字符
查看>>