zend framework创建自己的动作助手详解,zendframework本文实例讲述了zend framework创建自己的动作助手实现方法。分享给大家供大家参考,具体如下:
助手的抽象基类是zend_controller_action_helper_abstract,如要定义自己的助手,需要继承此类。
类的源代码如下:
_actioncontroller = $actioncontroller; return $this; } /** * retrieve current action controller * * @return zend_controller_action */ public function getactioncontroller() { return $this->_actioncontroller; } /** * retrieve front controller instance * * @return zend_controller_front */ public function getfrontcontroller() { return zend_controller_front::getinstance(); } /** * hook into action controller initialization * * @return void */ public function init() { } /** * hook into action controller predispatch() workflow * * @return void */ public function predispatch() { } /** * hook into action controller postdispatch() workflow * * @return void */ public function postdispatch() { } /** * getrequest() - * * @return zend_controller_request_abstract $request */ public function getrequest() { $controller = $this->getactioncontroller(); if (null === $controller) { $controller = $this->getfrontcontroller(); } return $controller->getrequest(); } /** * getresponse() - * * @return zend_controller_response_abstract $response */ public function getresponse() { $controller = $this->getactioncontroller(); if (null === $controller) { $controller = $this->getfrontcontroller(); } return $controller->getresponse(); } /** * getname() * * @return string */ public function getname() { $fullclassname = get_class($this); if (strpos($fullclassname, '_') !== false) { $helpername = strrchr($fullclassname, '_'); return ltrim($helpername, '_'); } elseif (strpos($fullclassname, '\\') !== false) { $helpername = strrchr($fullclassname, '\\'); return ltrim($helpername, '\\'); } else { return $fullclassname; } }}
助手基类提供的常用方法如下:
setactioncontroller() 用来设置当前的动作控制器。
init(),该方法在实例化时由助手经纪人触发,可用来触发助手的初始化过程;
动作链中多个控制器使用相同的助手时,如要恢复状态时将十分有用。
predispatch()分发动作之前触发。
postdispatch()分发过程结束时触发——即使predispatch()插件已经跳过了该动作。清理时大量使用。
getrequest() 获取当前的请求对象。
getresponse() 获取当前的响应对象。
getname() 获取助手名。获取了下划线后面的类名部分,没有下划线则获取类的全名。
例如,如果类名为zend_controller_action_helper_redirector,他将返回 redirector,如果类名为foomessage,将会返回全名。
举例说明自定义动作助手类
作用:解析传入的网址,返回各个部分。使用parse_url解析指定的网址。
用zendstudio新建一个zend framework项目helper_demo1。
新增文件:/helper_demo1/library/application/controller/action/helpers/urlparser.php
gethelper('urlparser'); var_dump($urlparser->parse('http://www.bkjia.com/article/80479.htm')); }}
以上介绍了自定义动作助手类,以及简单的使用方法。
需要注意的就是什么是助手类的前缀,助手类的名称以及助手的路径。
更多关于zend相关内容感兴趣的读者可查看本站专题:《zend framework框架入门教程》、《php优秀开发框架总结》、《yii框架入门及常用技巧总结》、《thinkphp入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家php程序设计有所帮助。
您可能感兴趣的文章:zend framework教程之zend_controller_plugin插件用法详解zend framework教程之响应对象的封装zend_controller_response实例详解zend framework教程之请求对象的封装zend_controller_request实例详解zend framework教程之动作的基类zend_controller_action详解zend framework教程之分发器zend_controller_dispatcher用法详解zend framework教程之前端控制器zend_controller_front用法详解zend framework动作助手redirector用法实例详解zend framework动作助手url用法详解zend framework动作助手json用法实例分析zend framework动作助手flashmessenger用法详解zend framework动作助手(zend_controller_action_helper)用法详解zend framework实现zend_view集成smarty模板系统的方法zend framework教程之路由功能zend_controller_router详解
http://www.bkjia.com/phpjc/1106901.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/1106901.htmltecharticlezend framework创建自己的动作助手详解,zendframework 本文实例讲述了zend framework创建自己的动作助手实现方法。分享给大家供大家参考,具体如...