⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 action.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category   Zend * @package    Zend_Controller * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License *//** Zend_Controller_Exception */require_once 'Zend/Controller/Action/Exception.php';/** Zend_Controller_Action_HelperBroker */require_once 'Zend/Controller/Action/HelperBroker.php';/** Zend_Controller_Front */require_once 'Zend/Controller/Front.php';/** Zend_Controller_Request_Abstract */require_once 'Zend/Controller/Request/Abstract.php';/** Zend_Controller_Response_Abstract */require_once 'Zend/Controller/Response/Abstract.php';/** * @category   Zend * @package    Zend_Controller * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */abstract class Zend_Controller_Action{    /**     * Word delimiters (used for normalizing view script paths)     * @var array     */    protected $_delimiters;    /**     * Array of arguments provided to the constructor, minus the     * {@link $_request Request object}.     * @var array     */    protected $_invokeArgs = array();    /**     * Front controller instance     * @var Zend_Controller_Front     */    protected $_frontController;    /**     * Zend_Controller_Request_Abstract object wrapping the request environment     * @var Zend_Controller_Request_Abstract     */    protected $_request = null;    /**     * Zend_Controller_Response_Abstract object wrapping the response     * @var Zend_Controller_Response_Abstract     */    protected $_response = null;    /**     * View script suffix; defaults to 'phtml'     * @see {render()}     * @var string     */    public $viewSuffix = 'phtml';    /**     * View object     * @var Zend_View_Interface     */    public $view;    /**     * Helper Broker to assist in routing help requests to the proper object     *     * @var Zend_Controller_Action_HelperBroker     */    protected $_helper = null;    /**     * Class constructor     *     * The request and response objects should be registered with the     * controller, as should be any additional optional arguments; these will be     * available via {@link getRequest()}, {@link getResponse()}, and     * {@link getInvokeArgs()}, respectively.     *     * When overriding the constructor, please consider this usage as a best     * practice and ensure that each is registered appropriately; the easiest     * way to do so is to simply call parent::__construct($request, $response,     * $invokeArgs).     *     * After the request, response, and invokeArgs are set, the     * {@link $_helper helper broker} is initialized.     *     * Finally, {@link init()} is called as the final action of     * instantiation, and may be safely overridden to perform initialization     * tasks; as a general rule, override {@link init()} instead of the     * constructor to customize an action controller's instantiation.     *     * @param Zend_Controller_Request_Abstract $request     * @param Zend_Controller_Response_Abstract $response     * @param array $invokeArgs Any additional invocation arguments     * @return void     */    public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())    {        $this->setRequest($request)             ->setResponse($response)             ->_setInvokeArgs($invokeArgs);        $this->_helper = new Zend_Controller_Action_HelperBroker($this);        $this->init();    }    /**     * Initialize object     *     * Called from {@link __construct()} as final step of object instantiation.     *     * @return void     */    public function init()    {    }    /**     * Initialize View object     *     * Initializes {@link $view} if not otherwise a Zend_View_Interface.     *     * If {@link $view} is not otherwise set, instantiates a new Zend_View     * object, using the 'views' subdirectory at the same level as the     * controller directory for the current module as the base directory.     * It uses this to set the following:     * - script path = views/scripts/     * - helper path = views/helpers/     * - filter path = views/filters/     *     * @return Zend_View_Interface     * @throws Zend_Controller_Exception if base view directory does not exist     */    public function initView()    {        if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {            return $this->view;        }        require_once 'Zend/View/Interface.php';        if (isset($this->view) && ($this->view instanceof Zend_View_Interface)) {            return $this->view;        }        $request = $this->getRequest();        $module  = $request->getModuleName();        $dirs    = $this->getFrontController()->getControllerDirectory();        if (empty($module) || !isset($dirs[$module])) {            $module = $this->getFrontController()->getDispatcher()->getDefaultModule();        }        $baseDir = dirname($dirs[$module]) . DIRECTORY_SEPARATOR . 'views';        if (!file_exists($baseDir) || !is_dir($baseDir)) {            throw new Zend_Controller_Exception('Missing base view directory ("' . $baseDir . '")');        }        require_once 'Zend/View.php';        $this->view = new Zend_View(array('basePath' => $baseDir));        return $this->view;    }    /**     * Render a view     *     * Renders a view. By default, views are found in the view script path as     * <controller>/<action>.phtml. You may change the script suffix by     * resetting {@link $viewSuffix}. You may omit the controller directory     * prefix by specifying boolean true for $noController.     *     * By default, the rendered contents are appended to the response. You may     * specify the named body content segment to set by specifying a $name.     *     * @see Zend_Controller_Response_Abstract::appendBody()     * @param  string|null $action Defaults to action registered in request object     * @param  string|null $name Response object named path segment to use; defaults to null     * @param  bool $noController  Defaults to false; i.e. use controller name as subdir in which to search for view script     * @return void     */    public function render($action = null, $name = null, $noController = false)    {        if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {            return $this->_helper->viewRenderer->render($action, $name, $noController);        }        $view   = $this->initView();        $script = $this->getViewScript($action, $noController);        $this->getResponse()->appendBody(            $view->render($script),            $name        );    }    /**     * Render a given view script     *     * Similar to {@link render()}, this method renders a view script. Unlike render(),     * however, it does not autodetermine the view script via {@link getViewScript()},     * but instead renders the script passed to it. Use this if you know the     * exact view script name and path you wish to use, or if using paths that do not     * conform to the spec defined with getViewScript().     *     * By default, the rendered contents are appended to the response. You may     * specify the named body content segment to set by specifying a $name.     *     * @param  string $script     * @param  string $name     * @return void     */    public function renderScript($script, $name = null)    {        if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {            return $this->_helper->viewRenderer->renderScript($script, $name);        }        $view = $this->initView();        $this->getResponse()->appendBody(            $view->render($script),            $name        );    }    /**     * Construct view script path     *     * Used by render() to determine the path to the view script.     *     * @param  string $action Defaults to action registered in request object     * @param  bool $noController  Defaults to false; i.e. use controller name as subdir in which to search for view script     * @return string     * @throws Zend_Controller_Exception with bad $action     */    public function getViewScript($action = null, $noController = null)    {        if (!$this->getInvokeArg('noViewRenderer') && $this->_helper->hasHelper('viewRenderer')) {            $viewRenderer = $this->_helper->getHelper('viewRenderer');            if (null !== $noController) {                $viewRenderer->setNoController($noController);            }            return $viewRenderer->getViewScript($action);        }        $request = $this->getRequest();        if (null === $action) {            $action = $request->getActionName();        } elseif (!is_string($action)) {            throw new Zend_Controller_Exception('Invalid action specifier for view render');        }        if (null === $this->_delimiters) {            $dispatcher = Zend_Controller_Front::getInstance()->getDispatcher();            $wordDelimiters = $dispatcher->getWordDelimiter();            $pathDelimiters = $dispatcher->getPathDelimiter();            $this->_delimiters = array_unique(array_merge($wordDelimiters, (array) $pathDelimiters));        }        $action = str_replace($this->_delimiters, '-', $action);        $script = $action . '.' . $this->viewSuffix;        if (!$noController) {            $controller = $request->getControllerName();            $controller = str_replace($this->_delimiters, '-', $controller);            $script = $controller . DIRECTORY_SEPARATOR . $script;        }        return $script;    }    /**     * Return the Request object     *     * @return Zend_Controller_Request_Abstract     */    public function getRequest()    {        return $this->_request;    }    /**     * Set the Request object     *     * @param Zend_Controller_Request_Abstract $request     * @return Zend_Controller_Action     */    public function setRequest(Zend_Controller_Request_Abstract $request)    {        $this->_request = $request;        return $this;    }    /**     * Return the Response object     *     * @return Zend_Controller_Response_Abstract     */    public function getResponse()    {        return $this->_response;    }    /**     * Set the Response object     *     * @param Zend_Controller_Response_Abstract $response     * @return Zend_Controller_Action     */    public function setResponse(Zend_Controller_Response_Abstract $response)    {        $this->_response = $response;        return $this;    }    /**     * Set invocation arguments

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -