View script integration

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');

uses
package Zend_Controller
subpackage Zend_Controller_Action_Helper
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Controller_Action_Helper_Abstract

 Methods

Clone - also make sure the view is cloned.

__clone() : void

Constructor

__construct(\Zend_View_Interface $view = null, array $options = array()) : void

Optionally set view object and options.

Parameters

$view

\Zend_View_Interface

$options

array

Use this helper as a method; proxies to setRender()

direct(string $action = null, string $name = null, boolean $noController = null) : void

Parameters

$action

string

$name

string

$noController

boolean

Retrieve current action controller

getActionController() : \Zend_Controller_Action
Inherited

Returns

\Zend_Controller_Action

Retrieve front controller instance

getFrontController() : \Zend_Controller_Front
Inherited

Returns

\Zend_Controller_Front

Get inflector

getInflector() : \Zend_Filter_Inflector

Returns

\Zend_Filter_Inflector

Get current module name

getModule() : string

Returns

string

Get module directory

getModuleDirectory() : string

Exceptions

\Zend_Controller_Action_Exception

Returns

string

getName()

getName() : string
Inherited

Returns

string

Retrieve neverController flag value

getNeverController() : boolean

Returns

boolean

Retrieve neverRender flag value

getNeverRender() : boolean

Returns

boolean

Retrieve noController flag value

getNoController() : boolean

Returns

boolean

Retrieve noRender flag value

getNoRender() : boolean

Returns

boolean

getRequest() -

getRequest() : \Zend_Controller_Request_Abstract
Inherited

Returns

\Zend_Controller_Request_Abstract$request

getResponse() -

getResponse() : \Zend_Controller_Response_Abstract
Inherited

Returns

\Zend_Controller_Response_Abstract$response

Retrieve named response segment name

getResponseSegment() : string

Returns

string

Retrieve view script name

getScriptAction() : string

Returns

string

Retrieve the current view basePath specification string

getViewBasePathSpec() : string

Returns

string

Get a view script based on an action and/or other variables

getViewScript(string $action = null, array $vars = array()) : string

Uses values found in current request if no values passed in $vars.

If \$_noController is set, uses \$_viewScriptPathNoControllerSpec; otherwise, uses \$_viewScriptPathSpec.

Parameters

$action

string

$vars

array

Returns

string

Retrieve the current view script path specification string (no controller variant)

getViewScriptPathNoControllerSpec() : string

Returns

string

Retrieve the current view script path specification string

getViewScriptPathSpec() : string

Returns

string

Get view script suffix

getViewSuffix() : string

Returns

string

init - initialize view

init() : void
inherited_from \Zend_Controller_Action_Helper_Abstract::init()

Hook into action controller initialization

init() : void
Inherited

Initialize the view object

initView(string $path = null, string $prefix = null, array $options = array()) : void

$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

Parameters

$path

string

$prefix

string

$options

array

Exceptions

\Zend_Controller_Action_Exception

postDispatch - auto render a view

postDispatch() : void

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
inherited_from \Zend_Controller_Action_Helper_Abstract::postDispatch()

Hook into action controller postDispatch() workflow

postDispatch() : void
Inherited

Hook into action controller preDispatch() workflow

preDispatch() : void
Inherited

Render a view based on path specifications

render(string $action = null, string $name = null, boolean $noController = null) : void

Renders a view based on the view script path specifications.

Parameters

$action

string

$name

string

$noController

boolean

Render a script based on specification variables

renderBySpec(string $action = null, array $vars = array(), string $name = null) : void

Pass an action, and one or more specification variables (view script suffix) to determine the view script path, and render that script.

Parameters

$action

string

$vars

array

$name

string

Render a view script (optionally to a named response segment)

renderScript(string $script, string $name = null) : void

Sets the noRender flag to true when called.

Parameters

$script

string

$name

string

setActionController()

setActionController(\Zend_Controller_Action $actionController = null) : \Zend_Controller_ActionHelper_Abstract
Inherited

Parameters

$actionController

\Zend_Controller_Action

Returns

\Zend_Controller_ActionHelper_AbstractProvides a fluent interface

Set inflector

setInflector(\Zend_Filter_Inflector $inflector, boolean $reference = false) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$inflector

\Zend_Filter_Inflector

$reference

boolean

Whether the moduleDir, target, and suffix should be set as references to ViewRenderer properties

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the neverController flag (i.e., whether or not to render into controller subdirectories)

setNeverController(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the neverRender flag (i.e., globally dis/enable autorendering)

setNeverRender(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the noController flag (i.e., whether or not to render into controller subdirectories)

setNoController(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the noRender flag (i.e., whether or not to autorender)

setNoRender(boolean $flag = true) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$flag

boolean

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set options for rendering a view script

setRender(string $action = null, string $name = null, boolean $noController = null) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$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

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the response segment name

setResponseSegment(string $name) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$name

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the view script to use

setScriptAction(string $name) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$name

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set the view object

setView(\Zend_View_Interface $view) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$view

\Zend_View_Interface

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set view basePath specification

setViewBasePathSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters

$path

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set view script path specification (no controller variant)

setViewScriptPathNoControllerSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer

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.

Parameters

$path

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set view script path specification

setViewScriptPathSpec(string $path) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters

$path

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Set view script suffix

setViewSuffix(string $suffix) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$suffix

string

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Generate a class prefix for helper and filter classes

_generateDefaultPrefix() : string

Returns

string

Retrieve base path based on location of current action controller

_getBasePath() : string

Returns

string

Get internal module directory representation

_getModuleDir() : string

Returns

string

Set inflector target

_setInflectorTarget(string $target) : void

Parameters

$target

string

Set internal module directory representation

_setModuleDir(string $dir) : void

Parameters

$dir

string

Set options

_setOptions(array $options) : \Zend_Controller_Action_Helper_ViewRenderer

Parameters

$options

array

Returns

\Zend_Controller_Action_Helper_ViewRendererProvides a fluent interface

Should the ViewRenderer render a view script?

_shouldRender() : boolean

Returns

boolean

Inflect based on provided vars

_translateSpec(array $vars = array()) : string

Allowed variables are:

  • :moduleDir - current module directory
  • :module - current module name
  • :controller - current controller name
  • :action - current action name
  • :suffix - view script file suffix

Parameters

$vars

array

Returns

string

 Properties

 

$view

$view : \Zend_View_Interface

Default

 

$_actionController

$_actionController : \Zend_Controller_Action

Default

null
 

Word delimiters

$_delimiters : array

Default

 

$_frontController

$_frontController : mixed

Default

null
 

$_inflector

$_inflector : \Zend_Filter_Inflector

Default

 

Inflector target

$_inflectorTarget : string

Default

''
 

Current module directory

$_moduleDir : string

Default

''
 

Whether or not to autorender using controller name as subdirectory; global setting (not reset at next invocation)

$_neverController : boolean

Default

false
 

Whether or not to autorender postDispatch; global setting (not reset at next invocation)

$_neverRender : boolean

Default

false
 

Whether or not to use a controller name as a subdirectory when rendering

$_noController : boolean

Default

false
 

Whether or not to autorender postDispatch; per controller/action setting (reset at next invocation)

$_noRender : boolean

Default

false
 

Characters representing path delimiters in the controller

$_pathDelimiters : string | array

Default

 

Which named segment of the response to utilize

$_responseSegment : string

Default

null
 

Which action view script to render

$_scriptAction : string

Default

null
 

View object basePath

$_viewBasePathSpec : string

Default

':moduleDir/views'
 

View script path specification string, minus controller segment

$_viewScriptPathNoControllerSpec : string

Default

':action.:suffix'
 

View script path specification string

$_viewScriptPathSpec : string

Default

':controller/:action.:suffix'
 

View script suffix

$_viewSuffix : string

Default

'phtml'