📄 front.php
字号:
/** * Return the router object. * * Instantiates a Zend_Controller_Router_Rewrite object if no router currently set. * * @return Zend_Controller_Router_Interface */ public function getRouter() { if (null == $this->_router) { require_once 'Zend/Controller/Router/Rewrite.php'; $this->setRouter(new Zend_Controller_Router_Rewrite()); } return $this->_router; } /** * Set the base URL used for requests * * Use to set the base URL segment of the REQUEST_URI to use when * determining PATH_INFO, etc. Examples: * - /admin * - /myapp * - /subdir/index.php * * Note that the URL should not include the full URI. Do not use: * - http://example.com/admin * - http://example.com/myapp * - http://example.com/subdir/index.php * * If a null value is passed, this can be used as well for autodiscovery (default). * * @param string $base * @return Zend_Controller_Front * @throws Zend_Controller_Exception for non-string $base */ public function setBaseUrl($base = null) { if (!is_string($base) && (null !== $base)) { throw new Zend_Controller_Exception('Rewrite base must be a string'); } $this->_baseUrl = $base; if ((null !== ($request = $this->getRequest())) && (method_exists($request, 'setBaseUrl'))) { $request->setBaseUrl($base); } return $this; } /** * Retrieve the currently set base URL * * @return string */ public function getBaseUrl() { $request = $this->getRequest(); if ((null !== $request) && method_exists($request, 'getBaseUrl')) { return $request->getBaseUrl(); } return $this->_baseUrl; } /** * Set the dispatcher object. The dispatcher is responsible for * taking a Zend_Controller_Dispatcher_Token object, instantiating the controller, and * call the action method of the controller. * * @param Zend_Controller_Dispatcher_Interface $dispatcher * @return Zend_Controller_Front */ public function setDispatcher(Zend_Controller_Dispatcher_Interface $dispatcher) { $this->_dispatcher = $dispatcher; return $this; } /** * Return the dispatcher object. * * @return Zend_Controller_Dispatcher_Interface */ public function getDispatcher() { /** * Instantiate the default dispatcher if one was not set. */ if (!$this->_dispatcher instanceof Zend_Controller_Dispatcher_Interface) { require_once 'Zend/Controller/Dispatcher/Standard.php'; $this->_dispatcher = new Zend_Controller_Dispatcher_Standard(); } return $this->_dispatcher; } /** * Set response class/object * * Set the response object. The response is a container for action * responses and headers. Usage is optional. * * If a class name is provided, instantiates a response object. * * @param string|Zend_Controller_Response_Abstract $response * @throws Zend_Controller_Exception if invalid response class * @return Zend_Controller_Front */ public function setResponse($response) { if (is_string($response)) { Zend_Loader::loadClass($response); $response = new $response(); } if (!$response instanceof Zend_Controller_Response_Abstract) { throw new Zend_Controller_Exception('Invalid response class'); } $this->_response = $response; return $this; } /** * Return the response object. * * @return null|Zend_Controller_Response_Abstract */ public function getResponse() { return $this->_response; } /** * Add or modify a parameter to use when instantiating an action controller * * @param string $name * @param mixed $value * @return Zend_Controller_Front */ public function setParam($name, $value) { $name = (string) $name; $this->_invokeParams[$name] = $value; return $this; } /** * Set parameters to pass to action controller constructors * * @param array $params * @return Zend_Controller_Front */ public function setParams(array $params) { $this->_invokeParams = array_merge($this->_invokeParams, $params); return $this; } /** * Retrieve a single parameter from the controller parameter stack * * @param string $name * @return mixed */ public function getParam($name) { if(isset($this->_invokeParams[$name])) { return $this->_invokeParams[$name]; } return null; } /** * Retrieve action controller instantiation parameters * * @return array */ public function getParams() { return $this->_invokeParams; } /** * Clear the controller parameter stack * * By default, clears all parameters. If a parameter name is given, clears * only that parameter; if an array of parameter names is provided, clears * each. * * @param null|string|array single key or array of keys for params to clear * @return Zend_Controller_Front */ public function clearParams($name = null) { if (null === $name) { $this->_invokeParams = array(); } elseif (is_string($name) && isset($this->_invokeParams[$name])) { unset($this->_invokeParams[$name]); } elseif (is_array($name)) { foreach ($name as $key) { if (is_string($key) && isset($this->_invokeParams[$key])) { unset($this->_invokeParams[$key]); } } } return $this; } /** * Register a plugin. * * @param Zend_Controller_Plugin_Abstract $plugin * @param int $stackIndex Optional; stack index for plugin * @return Zend_Controller_Front */ public function registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null) { $this->_plugins->registerPlugin($plugin, $stackIndex); return $this; } /** * Unregister a plugin. * * @param string|Zend_Controller_Plugin_Abstract $plugin Plugin class or object to unregister * @return Zend_Controller_Front */ public function unregisterPlugin($plugin) { $this->_plugins->unregisterPlugin($plugin); return $this; } /** * Is a particular plugin registered? * * @param string $class * @return bool */ public function hasPlugin($class) { return $this->_plugins->hasPlugin($class); } /** * Retrieve a plugin or plugins by class * * @param string $class * @return false|Zend_Controller_Plugin_Abstract|array */ public function getPlugin($class) { return $this->_plugins->getPlugin($class); } /** * Retrieve all plugins * * @return array */ public function getPlugins() { return $this->_plugins->getPlugins(); } /** * Set the throwExceptions flag and retrieve current status * * Set whether exceptions encounted in the dispatch loop should be thrown * or caught and trapped in the response object. * * Default behaviour is to trap them in the response object; call this * method to have them thrown. * * Passing no value will return the current value of the flag; passing a * boolean true or false value will set the flag and return the current * object instance. * * @param boolean $flag Defaults to null (return flag state) * @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean */ public function throwExceptions($flag = null) { if ($flag !== null) { $this->_throwExceptions = (bool) $flag; return $this; } return $this->_throwExceptions; } /** * Set whether {@link dispatch()} should return the response without first * rendering output. By default, output is rendered and dispatch() returns * nothing. * * @param boolean $flag * @return boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean */ public function returnResponse($flag = null) { if (true === $flag) { $this->_returnResponse = true; return $this; } elseif (false === $flag) { $this->_returnResponse = false; return $this; } return $this->_returnResponse; } /** * Dispatch an HTTP request to a controller/action. * * @param Zend_Controller_Request_Abstract|null $request * @param Zend_Controller_Response_Abstract|null $response * @return void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true */ public function dispatch(Zend_Controller_Request_Abstract $request = null, Zend_Controller_Response_Abstract $response = null) { if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('Zend_Controller_Plugin_ErrorHandler')) { // Register with stack index of 100 require_once 'Zend/Controller/Plugin/ErrorHandler.php'; $this->_plugins->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(), 100); } if (!$this->getParam('noViewRenderer') && !Zend_Controller_Action_HelperBroker::hasHelper('viewRenderer')) { require_once 'Zend/Controller/Action/Helper/ViewRenderer.php'; Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer()); } /** * Instantiate default request object (HTTP version) if none provided */ if (null !== $request) { $this->setRequest($request); } elseif ((null === $request) && (null === ($request = $this->getRequest()))) { require_once 'Zend/Controller/Request/Http.php'; $request = new Zend_Controller_Request_Http(); $this->setRequest($request); } /** * Set base URL of request object, if available */ if (is_callable(array($this->_request, 'setBaseUrl'))) { if (null !== $this->_baseUrl) { $this->_request->setBaseUrl($this->_baseUrl); } } /** * Instantiate default response object (HTTP version) if none provided */ if (null !== $response) { $this->setResponse($response); } elseif ((null === $this->_response) && (null === ($this->_response = $this->getResponse()))) { require_once 'Zend/Controller/Response/Http.php'; $response = new Zend_Controller_Response_Http(); $this->setResponse($response); } /** * Register request and response objects with plugin broker */ $this->_plugins ->setRequest($this->_request) ->setResponse($this->_response); /** * Initialize router */ $router = $this->getRouter(); $router->setParams($this->getParams()); /** * Initialize dispatcher */ $dispatcher = $this->getDispatcher(); $dispatcher->setParams($this->getParams()) ->setResponse($this->_response); // Begin dispatch try { /** * Route request to controller/action, if a router is provided */ /** * Notify plugins of router startup */ $this->_plugins->routeStartup($this->_request); $router->route($this->_request); /** * Notify plugins of router completion */ $this->_plugins->routeShutdown($this->_request); /** * Notify plugins of dispatch loop startup */ $this->_plugins->dispatchLoopStartup($this->_request); /** * Attempt to dispatch the controller/action. If the $this->_request * indicates that it needs to be dispatched, move to the next * action in the request. */ do { $this->_request->setDispatched(true); /** * Notify plugins of dispatch startup */ $this->_plugins->preDispatch($this->_request); /** * Skip requested action if preDispatch() has reset it */ if (!$this->_request->isDispatched()) { continue; } /** * Dispatch request */ try { $dispatcher->dispatch($this->_request, $this->_response); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->_response->setException($e); } /** * Notify plugins of dispatch completion */ $this->_plugins->postDispatch($this->_request); } while (!$this->_request->isDispatched()); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->_response->setException($e); } /** * Notify plugins of dispatch loop completion */ try { $this->_plugins->dispatchLoopShutdown(); } catch (Exception $e) { if ($this->throwExceptions()) { throw $e; } $this->_response->setException($e); } if ($this->returnResponse()) { return $this->_response; } $this->_response->sendResponse(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -