📄 viewrenderer.php
字号:
// Register view with action controller (unless already registered) if ((null !== $this->_actionController) && (null === $this->_actionController->view)) { $this->_actionController->view = $this->view; $this->_actionController->viewSuffix = $this->_viewSuffix; } } /** * init - initialize view * * @return void */ public function init() { if ($this->getFrontController()->getParam('noViewRenderer')) { return; } $this->initView(); } /** * Set view basePath specification * * Specification can contain one or more of the following: * - :moduleDir - current module directory * - :controller - name of current controller in the request * - :action - name of current action in the request * - :module - name of current module in the request * * @param string $path * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setViewBasePathSpec($path) { $this->_viewBasePathSpec = (string) $path; return $this; } /** * Retrieve the current view basePath specification string * * @return string */ public function getViewBasePathSpec() { return $this->_viewBasePathSpec; } /** * Set view script path specification * * Specification can contain one or more of the following: * - :moduleDir - current module directory * - :controller - name of current controller in the request * - :action - name of current action in the request * - :module - name of current module in the request * * @param string $path * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setViewScriptPathSpec($path) { $this->_viewScriptPathSpec = (string) $path; return $this; } /** * Retrieve the current view script path specification string * * @return string */ public function getViewScriptPathSpec() { return $this->_viewScriptPathSpec; } /** * Set view script path specification (no controller variant) * * Specification can contain one or more of the following: * - :moduleDir - current module directory * - :controller - name of current controller in the request * - :action - name of current action in the request * - :module - name of current module in the request * * :controller will likely be ignored in this variant. * * @param string $path * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setViewScriptPathNoControllerSpec($path) { $this->_viewScriptPathNoControllerSpec = (string) $path; return $this; } /** * Retrieve the current view script path specification string (no controller variant) * * @return string */ public function getViewScriptPathNoControllerSpec() { return $this->_viewScriptPathNoControllerSpec; } /** * Get a view script based on an action and/or other variables * * Uses values found in current request if no values passed in $vars. * * If {@link $_noController} is set, uses {@link $_viewScriptPathNoControllerSpec}; * otherwise, uses {@link $_viewScriptPathSpec}. * * @param string $action * @param array $vars * @return string */ public function getViewScript($action = null, array $vars = array()) { $request = $this->getRequest(); if ((null === $action) && (!isset($vars['action']))) { $action = $this->getScriptAction(); if (null === $action) { $action = $request->getActionName(); } $vars['action'] = $action; } elseif (null !== $action) { $vars['action'] = $action; } $inflector = $this->getInflector(); if ($this->getNoController() || $this->getNeverController()) { $this->_setInflectorTarget($this->getViewScriptPathNoControllerSpec()); } else { $this->_setInflectorTarget($this->getViewScriptPathSpec()); } return $this->_translateSpec($vars); } /** * Set the neverRender flag (i.e., globally dis/enable autorendering) * * @param boolean $flag * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setNeverRender($flag = true) { $this->_neverRender = ($flag) ? true : false; return $this; } /** * Retrieve neverRender flag value * * @return boolean */ public function getNeverRender() { return $this->_neverRender; } /** * Set the noRender flag (i.e., whether or not to autorender) * * @param boolean $flag * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setNoRender($flag = true) { $this->_noRender = ($flag) ? true : false; return $this; } /** * Retrieve noRender flag value * * @return boolean */ public function getNoRender() { return $this->_noRender; } /** * Set the view script to use * * @param string $name * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setScriptAction($name) { $this->_scriptAction = (string) $name; return $this; } /** * Retrieve view script name * * @return string */ public function getScriptAction() { return $this->_scriptAction; } /** * Set the response segment name * * @param string $name * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setResponseSegment($name) { if (null === $name) { $this->_responseSegment = null; } else { $this->_responseSegment = (string) $name; } return $this; } /** * Retrieve named response segment name * * @return string */ public function getResponseSegment() { return $this->_responseSegment; } /** * Set the noController flag (i.e., whether or not to render into controller subdirectories) * * @param boolean $flag * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setNoController($flag = true) { $this->_noController = ($flag) ? true : false; return $this; } /** * Retrieve noController flag value * * @return boolean */ public function getNoController() { return $this->_noController; } /** * Set the neverController flag (i.e., whether or not to render into controller subdirectories) * * @param boolean $flag * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setNeverController($flag = true) { $this->_neverController = ($flag) ? true : false; return $this; } /** * Retrieve neverController flag value * * @return boolean */ public function getNeverController() { return $this->_neverController; } /** * Set view script suffix * * @param string $suffix * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setViewSuffix($suffix) { $this->_viewSuffix = (string) $suffix; return $this; } /** * Get view script suffix * * @return string */ public function getViewSuffix() { return $this->_viewSuffix; } /** * Set options for rendering a view script * * @param string $action View script to render * @param string $name Response named segment to render to * @param boolean $noController Whether or not to render within a subdirectory named after the controller * @return Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface */ public function setRender($action = null, $name = null, $noController = null) { if (null !== $action) { $this->setScriptAction($action); } if (null !== $name) { $this->setResponseSegment($name); } if (null !== $noController) { $this->setNoController($noController); } return $this; } /** * Inflect based on provided vars * * Allowed variables are: * - :moduleDir - current module directory * - :module - current module name * - :controller - current controller name * - :action - current action name * - :suffix - view script file suffix * * @param array $vars * @return string */ protected function _translateSpec(array $vars = array()) { $inflector = $this->getInflector(); $request = $this->getRequest(); $dispatcher = $this->_frontController->getDispatcher(); $module = $dispatcher->formatModuleName($request->getModuleName()); $controller = substr($dispatcher->formatControllerName($request->getControllerName()), 0, -10); $action = $dispatcher->formatActionName($request->getActionName()); $params = compact('module', 'controller', 'action'); foreach ($vars as $key => $value) { switch ($key) { case 'module': case 'controller': case 'action': case 'moduleDir': case 'suffix': $params[$key] = (string) $value; break; default: break; } } if (isset($params['suffix'])) { $origSuffix = $this->getViewSuffix(); $this->setViewSuffix($params['suffix']); } if (isset($moduleDir)) { $origModuleDir = $this->_getModuleDir(); $this->_setModuleDir($params['moduleDir']); } $filtered = $inflector->filter($params); if (isset($params['suffix'])) { $this->setViewSuffix($origSuffix); } if (isset($moduleDir)) { $this->_setModuleDir($origModuleDir); } return $filtered; } /** * Render a view script (optionally to a named response segment) * * Sets the noRender flag to true when called. * * @param string $script * @param string $name * @return void */ public function renderScript($script, $name = null) { if (null === $name) { $name = $this->getResponseSegment(); } $this->getResponse()->appendBody( $this->view->render($script), $name ); $this->setNoRender(); } /** * Render a view based on path specifications * * Renders a view based on the view script path specifications. * * @param string $action * @param string $name * @param boolean $noController * @return void */ public function render($action = null, $name = null, $noController = null) { $this->setRender($action, $name, $noController); $path = $this->getViewScript(); $this->renderScript($path, $name); } /** * Render a script based on specification variables * * Pass an action, and one or more specification variables (view script suffix) * to determine the view script path, and render that script. * * @param string $action * @param array $vars * @param string $name * @return void */ public function renderBySpec($action = null, array $vars = array(), $name = null) { if (null !== $name) { $this->setResponseSegment($name); } $path = $this->getViewScript($action, $vars); $this->renderScript($path); } /** * postDispatch - auto render a view * * Only autorenders if: * - _noRender is false * - action controller is present * - request has not been re-dispatched (i.e., _forward() has not been called) * - response is not a redirect * * @return void */ public function postDispatch() { if ($this->_shouldRender()) { $this->render(); } } /** * Should the ViewRenderer render a view script? * * @return boolean */ protected function _shouldRender() { return (!$this->getFrontController()->getParam('noViewRenderer') && !$this->_neverRender && !$this->_noRender && (null !== $this->_actionController) && $this->getRequest()->isDispatched() && !$this->getResponse()->isRedirect() ); } /** * Use this helper as a method; proxies to setRender() * * @param string $action * @param string $name * @param boolean $noController * @return void */ public function direct($action = null, $name = null, $noController = null) { $this->setRender($action, $name, $noController); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -