API Documentation

Zend/Controller/Action/Helper/ViewRenderer.php

Show: inherited
Table of Contents

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  
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 24594 2012-01-05 21:27:01Z matthew $  

\Zend_Controller_Action_Helper_ViewRenderer

Package: Zend\Controller\Zend\Controller\Action\Helper

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

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
\Zend_Controller_Action_Helper_Abstract  

Properties

Propertyprotectedarray  $_delimiters= ''

Word delimiters

Details
Type
array
Propertyprotected\Zend_Filter_Inflector  $_inflector= ''

Details
Type
\Zend_Filter_Inflector
Propertyprotectedstring  $_inflectorTarget= ''''

Inflector target

Default value''Details
Type
string
Propertyprotectedstring  $_moduleDir= ''''

Current module directory

Default value''Details
Type
string
Propertyprotectedboolean  $_neverController= 'false'

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

Default valuefalseDetails
Type
boolean
Propertyprotectedboolean  $_neverRender= 'false'

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

Default valuefalseDetails
Type
boolean
Propertyprotectedboolean  $_noController= 'false'

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

Default valuefalseDetails
Type
boolean
Propertyprotectedboolean  $_noRender= 'false'

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

Default valuefalseDetails
Type
boolean
Propertyprotectedstring|array  $_pathDelimiters= ''

Characters representing path delimiters in the controller

Details
Type
stringarray
Propertyprotectedstring  $_responseSegment= 'null'

Which named segment of the response to utilize

Default valuenullDetails
Type
string
Propertyprotectedstring  $_scriptAction= 'null'

Which action view script to render

Default valuenullDetails
Type
string
Propertyprotectedstring  $_viewBasePathSpec= '':moduleDir/views''

View object basePath

Default value':moduleDir/views'Details
Type
string
Propertyprotectedstring  $_viewScriptPathNoControllerSpec= '':action.:suffix''

View script path specification string, minus controller segment

Default value':action.:suffix'Details
Type
string
Propertyprotectedstring  $_viewScriptPathSpec= '':controller/:action.:suffix''

View script path specification string

Default value':controller/:action.:suffix'Details
Type
string
Propertyprotectedstring  $_viewSuffix= ''phtml''

View script suffix

Default value'phtml'Details
Type
string
Propertypublic\Zend_View_Interface  $view= ''

Details
Type
\Zend_View_Interface

Methods

methodpublic__clone( ) : void

Clone - also make sure the view is cloned.

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

Constructor

Optionally set view object and options.

Parameters
Name Type Description
$view \Zend_View_Interface
$options array
methodprotected_generateDefaultPrefix( ) : string

Generate a class prefix for helper and filter classes

Returns
Type Description
string
methodprotected_getBasePath( ) : string

Retrieve base path based on location of current action controller

Returns
Type Description
string
methodprotected_getModuleDir( ) : string

Get internal module directory representation

Returns
Type Description
string
methodprotected_setInflectorTarget( string $target ) : void

Set inflector target

Parameters
Name Type Description
$target string
methodprotected_setModuleDir( string $dir ) : void

Set internal module directory representation

Parameters
Name Type Description
$dir string
methodprotected_setOptions( array $options ) : \Zend_Controller_Action_Helper_ViewRenderer

Set options

Parameters
Name Type Description
$options array
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodprotected_shouldRender( ) : boolean

Should the ViewRenderer render a view script?

Returns
Type Description
boolean
methodprotected_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

Parameters
Name Type Description
$vars array
Returns
Type Description
string
methodpublicdirect( string $action = null, string $name = null, boolean $noController = null ) : void

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

Parameters
Name Type Description
$action string
$name string
$noController boolean
methodpublicgetInflector( ) : \Zend_Filter_Inflector

Get inflector

Returns
Type Description
\Zend_Filter_Inflector
methodpublicgetModule( ) : string

Get current module name

Returns
Type Description
string
methodpublicgetModuleDirectory( ) : string

Get module directory

Returns
Type Description
string
Throws
Exception Description
\Zend_Controller_Action_Exception
methodpublicgetNeverController( ) : boolean

Retrieve neverController flag value

Returns
Type Description
boolean
methodpublicgetNeverRender( ) : boolean

Retrieve neverRender flag value

Returns
Type Description
boolean
methodpublicgetNoController( ) : boolean

Retrieve noController flag value

Returns
Type Description
boolean
methodpublicgetNoRender( ) : boolean

Retrieve noRender flag value

Returns
Type Description
boolean
methodpublicgetResponseSegment( ) : string

Retrieve named response segment name

Returns
Type Description
string
methodpublicgetScriptAction( ) : string

Retrieve view script name

Returns
Type Description
string
methodpublicgetViewBasePathSpec( ) : string

Retrieve the current view basePath specification string

Returns
Type Description
string
methodpublicgetViewScript( 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 {@link $_noController} is set, uses {@link $_viewScriptPathNoControllerSpec}; otherwise, uses {@link $_viewScriptPathSpec}.

Parameters
Name Type Description
$action string
$vars array
Returns
Type Description
string
methodpublicgetViewScriptPathNoControllerSpec( ) : string

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

Returns
Type Description
string
methodpublicgetViewScriptPathSpec( ) : string

Retrieve the current view script path specification string

Returns
Type Description
string
methodpublicgetViewSuffix( ) : string

Get view script suffix

Returns
Type Description
string
methodpublicinit( ) : void

init - initialize view

methodpublicinitView( 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

Parameters
Name Type Description
$path string
$prefix string
$options array
Throws
Exception Description
\Zend_Controller_Action_Exception
methodpublicpostDispatch( ) : 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

methodpublicrender( 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.

Parameters
Name Type Description
$action string
$name string
$noController boolean
methodpublicrenderBySpec( 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.

Parameters
Name Type Description
$action string
$vars array
$name string
methodpublicrenderScript( string $script, string $name = null ) : void

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

Sets the noRender flag to true when called.

Parameters
Name Type Description
$script string
$name string
methodpublicsetInflector( \Zend_Filter_Inflector $inflector, boolean $reference = false ) : \Zend_Controller_Action_Helper_ViewRenderer

Set inflector

Parameters
Name Type Description
$inflector \Zend_Filter_Inflector
$reference boolean

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

Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetNeverController( boolean $flag = true ) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters
Name Type Description
$flag boolean
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetNeverRender( boolean $flag = true ) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters
Name Type Description
$flag boolean
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetNoController( boolean $flag = true ) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters
Name Type Description
$flag boolean
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetNoRender( boolean $flag = true ) : \Zend_Controller_Action_Helper_ViewRenderer

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

Parameters
Name Type Description
$flag boolean
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetRender( string $action = null, string $name = null, boolean $noController = null ) : \Zend_Controller_Action_Helper_ViewRenderer

Set options for rendering a view script

Parameters
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

Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetResponseSegment( string $name ) : \Zend_Controller_Action_Helper_ViewRenderer

Set the response segment name

Parameters
Name Type Description
$name string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetScriptAction( string $name ) : \Zend_Controller_Action_Helper_ViewRenderer

Set the view script to use

Parameters
Name Type Description
$name string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetView( \Zend_View_Interface $view ) : \Zend_Controller_Action_Helper_ViewRenderer

Set the view object

Parameters
Name Type Description
$view \Zend_View_Interface
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetViewBasePathSpec( 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

Parameters
Name Type Description
$path string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetViewScriptPathNoControllerSpec( 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.

Parameters
Name Type Description
$path string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetViewScriptPathSpec( 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

Parameters
Name Type Description
$path string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
methodpublicsetViewSuffix( string $suffix ) : \Zend_Controller_Action_Helper_ViewRenderer

Set view script suffix

Parameters
Name Type Description
$suffix string
Returns
Type Description
\Zend_Controller_Action_Helper_ViewRenderer Provides a fluent interface
Documentation was generated by DocBlox 0.15.1.