Controller/Action/Helper/ViewRenderer.php
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
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Controller
- Subpackage
- Zend_Controller_Action_Helper
- Version
- $Id: ViewRenderer.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Controller_Action_Helper_ViewRenderer
Zend_Controller_Action_Helper_ViewRenderer provides transparent view integration for action controllers. It allows you to create a view object once, and populate it throughout all actions. Several global options may be set:
- noController: if set true, render() will not look for view scripts in subdirectories named after the controller
- viewSuffix: what view script filename suffix to use
The helper autoinitializes the action controller view preDispatch(). It determines the path to the class file, and then determines the view base directory from there. It also uses the module name as a class prefix for helpers and views such that if your module name is 'Search', it will set the helper class prefix to 'Search_View_Helper' and the filter class prefix to ; 'Search_View_Filter'.
Usage:
// In your bootstrap:
Zend_Controller_Action_HelperBroker::addHelper(new Zend_Controller_Action_Helper_ViewRenderer());
// In your action controller methods:
$viewHelper = $this->_helper->getHelper('view');
// Don't use controller subdirectories
$viewHelper->setNoController(true);
// Specify a different script to render:
$this->_helper->viewRenderer('form');
- Parent(s)
- \Zend_Controller_Action_Helper_Abstract
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Uses
- \global\Zend_Controller_Action_Helper_Abstract
Properties


\Zend_Controller_Action $_actionController = null
null
Details

mixed $_frontController = null
null
Details- Type
- mixed
- Inherited_from
- \Zend_Controller_Action_Helper_Abstract::$$_frontController


boolean $_neverController = false
false
Details- Type
- boolean


boolean $_neverRender = false
false
Details- Type
- boolean


boolean $_noController = false
false
Details- Type
- boolean


boolean $_noRender = false
false
Details- Type
- boolean


string|array $_pathDelimiters
- Type
- string | array


string $_responseSegment = null
null
Details- Type
- string


string $_viewBasePathSpec = ':moduleDir/views'
':moduleDir/views'
Details- Type
- string


string $_viewScriptPathNoControllerSpec = ':action.:suffix'
':action.:suffix'
Details- Type
- string


string $_viewScriptPathSpec = ':controller/:action.:suffix'
':controller/:action.:suffix'
Details- Type
- string
Methods


__construct(\Zend_View_Interface $view = null, array $options = array()) : void
Constructor
Optionally set view object and options.
Name | Type | Description |
---|---|---|
$view | \Zend_View_Interface | |
$options | array |


_generateDefaultPrefix() : string
Generate a class prefix for helper and filter classes
Type | Description |
---|---|
string |


_getBasePath() : string
Retrieve base path based on location of current action controller
Type | Description |
---|---|
string |


_setInflectorTarget(string $target) : void
Set inflector target
Name | Type | Description |
---|---|---|
$target | string |


_setModuleDir(string $dir) : void
Set internal module directory representation
Name | Type | Description |
---|---|---|
$dir | string |


_setOptions(array $options) : \Zend_Controller_Action_Helper_ViewRenderer
Set options
Name | Type | Description |
---|---|---|
$options | array |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


_translateSpec(array $vars = array()) : string
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
Name | Type | Description |
---|---|---|
$vars | array |
Type | Description |
---|---|
string |


direct(string $action = null, string $name = null, boolean $noController = null) : void
Use this helper as a method; proxies to setRender()
Name | Type | Description |
---|---|---|
$action | string | |
$name | string | |
$noController | boolean |


getActionController() : \Zend_Controller_Action
Retrieve current action controller
Inherited from: \Zend_Controller_Action_Helper_Abstract::getActionController()Type | Description |
---|---|
\Zend_Controller_Action |


getFrontController() : \Zend_Controller_Front
Retrieve front controller instance
Inherited from: \Zend_Controller_Action_Helper_Abstract::getFrontController()Type | Description |
---|---|
\Zend_Controller_Front |


getModuleDirectory() : string
Get module directory
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Controller_Action_Exception |


getRequest() : \Zend_Controller_Request_Abstract
Type | Description |
---|---|
\Zend_Controller_Request_Abstract | $request |


getResponse() : \Zend_Controller_Response_Abstract
Type | Description |
---|---|
\Zend_Controller_Response_Abstract | $response |


getViewBasePathSpec() : string
Retrieve the current view basePath specification string
Type | Description |
---|---|
string |


getViewScript(string $action = null, array $vars = array()) : string
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 $_noController is set, uses $_viewScriptPathNoControllerSpec; otherwise, uses $_viewScriptPathSpec.
Name | Type | Description |
---|---|---|
$action | string | |
$vars | array |
Type | Description |
---|---|
string |


getViewScriptPathNoControllerSpec() : string
Retrieve the current view script path specification string (no controller variant)
Type | Description |
---|---|
string |


getViewScriptPathSpec() : string
Retrieve the current view script path specification string
Type | Description |
---|---|
string |


initView(string $path = null, string $prefix = null, array $options = array()) : void
Initialize the view object
$options may contain the following keys: - neverRender - flag dis/enabling postDispatch() autorender (affects all subsequent calls) - noController - flag indicating whether or not to look for view scripts in subdirectories named after the controller - noRender - flag indicating whether or not to autorender postDispatch() - responseSegment - which named response segment to render a view script to - scriptAction - what action script to render - viewBasePathSpec - specification to use for determining view base path - viewScriptPathSpec - specification to use for determining view script paths - viewScriptPathNoControllerSpec - specification to use for determining view script paths when noController flag is set - viewSuffix - what view script filename suffix to use
Name | Type | Description |
---|---|---|
$path | string | |
$prefix | string | |
$options | array |
Exception | Description |
---|---|
\Zend_Controller_Action_Exception |


postDispatch() : void
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


preDispatch() : void
Hook into action controller preDispatch() workflow
Inherited from: \Zend_Controller_Action_Helper_Abstract::preDispatch()

render(string $action = null, string $name = null, boolean $noController = null) : void
Render a view based on path specifications
Renders a view based on the view script path specifications.
Name | Type | Description |
---|---|---|
$action | string | |
$name | string | |
$noController | boolean |


renderBySpec(string $action = null, array $vars = array(), string $name = null) : void
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.
Name | Type | Description |
---|---|---|
$action | string | |
$vars | array | |
$name | string |


renderScript(string $script, string $name = null) : void
Render a view script (optionally to a named response segment)
Sets the noRender flag to true when called.
Name | Type | Description |
---|---|---|
$script | string | |
$name | string |


setActionController(\Zend_Controller_Action $actionController = null) : \Zend_Controller_ActionHelper_Abstract
setActionController()
Inherited from: \Zend_Controller_Action_Helper_Abstract::setActionController()Name | Type | Description |
---|---|---|
$actionController | \Zend_Controller_Action |
Type | Description |
---|---|
\Zend_Controller_ActionHelper_Abstract | Provides a fluent interface |


setInflector(\Zend_Filter_Inflector $inflector, boolean $reference = false) : \Zend_Controller_Action_Helper_ViewRenderer
Set inflector
Name | Type | Description |
---|---|---|
$inflector | \Zend_Filter_Inflector | |
$reference | boolean | Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setNeverController(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer
Set the neverController flag (i.e., whether or not to render into controller subdirectories)
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setNeverRender(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer
Set the neverRender flag (i.e., globally dis/enable autorendering)
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setNoController(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer
Set the noController flag (i.e., whether or not to render into controller subdirectories)
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setNoRender(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer
Set the noRender flag (i.e., whether or not to autorender)
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setRender(string $action = null, string $name = null, boolean $noController = null) : \Zend_Controller_Action_Helper_ViewRenderer
Set options for rendering a view script
Name | Type | Description |
---|---|---|
$action | string | View script to render |
$name | string | Response named segment to render to |
$noController | boolean | Whether or not to render within a subdirectory named after the controller |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setResponseSegment(string $name) : \Zend_Controller_Action_Helper_ViewRenderer
Set the response segment name
Name | Type | Description |
---|---|---|
$name | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setScriptAction(string $name) : \Zend_Controller_Action_Helper_ViewRenderer
Set the view script to use
Name | Type | Description |
---|---|---|
$name | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setView(\Zend_View_Interface $view) : \Zend_Controller_Action_Helper_ViewRenderer
Set the view object
Name | Type | Description |
---|---|---|
$view | \Zend_View_Interface |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setViewBasePathSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer
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
Name | Type | Description |
---|---|---|
$path | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setViewScriptPathNoControllerSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer
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.
Name | Type | Description |
---|---|---|
$path | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setViewScriptPathSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer
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
Name | Type | Description |
---|---|---|
$path | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |


setViewSuffix(string $suffix) : \Zend_Controller_Action_Helper_ViewRenderer
Set view script suffix
Name | Type | Description |
---|---|---|
$suffix | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_ViewRenderer | Provides a fluent interface |