<?php /** * @see Zend_Controller_Action */require_once 'Zend/Controller/Action.php'; abstract class Zend_Controller_Action_Helper_Abstract{ /** * $_actionController * * @var Zend_Controller_Action $_actionController */ protected $_actionController = null; /** * @var mixed $_frontController */ protected $_frontController = null; /** * setActionController() * * @param Zend_Controller_Action $actionController * @return Zend_Controller_ActionHelper_Abstract Provides a fluent interface */ public function setActionController(Zend_Controller_Action $actionController = null) { $this->_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; } }}
<?phprequire_once 'Zend/Controller/Action/Helper/Abstract.php'; class Application_Controller_Action_Helpers_UrlParser extends Zend_Controller_Action_Helper_Abstract{ public function __construct() { } /** * Parse url * * @param String $url * @return Array part of url */ public function parse($url) { return parse_url($url); }}
<?phpclass Bootstrap extends Zend_Application_Bootstrap_Bootstrap{ protected function _initAutoload() { $autoloader = Zend_Loader_Autoloader::getInstance(); $autoloader->registerNamespace(array('Application_')); } protected function _initActionHelpers() { //用前缀形式 //Zend_Controller_Action_HelperBroker::addPrefix('Application_Controller_Action_Helpers'); //指定目录和前缀 //Zend_Controller_Action_HelperBroker::addPath('/www/helper_demo1/library/Application/Controller/Action/Helpers', // 'Application_Controller_Action_Helpers'); //new一个助手类传入 Zend_Controller_Action_HelperBroker::addHelper(new Application_Controller_Action_Helpers_UrlParser); }}
<?phpclass IndexController extends Zend_Controller_Action{ public function init() { /* Initialize action controller here */ } public function indexAction() { $urlParser = $this->_helper->getHelper('UrlParser'); var_dump($urlParser->parse('http://blog.csdn.net/mengxiangbaidu/article/details/7236249')); }}
下一篇 PHP 是什么?