Zend Framework  1.12
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
Zend_Controller_Action Class Reference

Public Member Functions

 __construct (Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs=array())
 Class constructor.
 
 init ()
 Initialize object.
 
 initView ()
 Initialize View object.
 
 render ($action=null, $name=null, $noController=false)
 Render a view.
 
 renderScript ($script, $name=null)
 Render a given view script.
 
 getViewScript ($action=null, $noController=null)
 Construct view script path.
 
 getRequest ()
 Return the Request object.
 
 setRequest (Zend_Controller_Request_Abstract $request)
 Set the Request object.
 
 getResponse ()
 Return the Response object.
 
 setResponse (Zend_Controller_Response_Abstract $response)
 Set the Response object.
 
 getInvokeArgs ()
 Return the array of constructor arguments (minus the Request object)
 
 getInvokeArg ($key)
 Return a single invocation argument.
 
 getHelper ($helperName)
 Get a helper by name.
 
 getHelperCopy ($helperName)
 Get a clone of a helper by name.
 
 setFrontController (Zend_Controller_Front $front)
 Set the front controller instance.
 
 getFrontController ()
 Retrieve Front Controller.
 
 preDispatch ()
 Pre-dispatch routines.
 
 postDispatch ()
 Post-dispatch routines.
 
 __call ($methodName, $args)
 Proxy for undefined methods.
 
 dispatch ($action)
 Dispatch the requested action.
 
 run (Zend_Controller_Request_Abstract $request=null, Zend_Controller_Response_Abstract $response=null)
 Call the action specified in the request object, and return a response.
 
 getParam ($paramName, $default=null)
 Gets a parameter from the Request object.
 
 setParam ($paramName, $value)
 Set a parameter in the Request object.
 
 hasParam ($paramName)
 Determine whether a given parameter exists in the Request object.
 
 getAllParams ()
 Return all parameters in the Request object as an associative array.
 
 forward ($action, $controller=null, $module=null, array $params=null)
 Forward to another controller/action.
 
 redirect ($url, array $options=array())
 Redirect to another URL.
 

Public Attributes

 $viewSuffix = 'phtml'
 
 $view
 

Protected Member Functions

 _setInvokeArgs (array $args=array())
 Set invocation arguments.
 
 _getParam ($paramName, $default=null)
 Gets a parameter from the Request object.
 
 _setParam ($paramName, $value)
 Set a parameter in the Request object.
 
 _hasParam ($paramName)
 Determine whether a given parameter exists in the Request object.
 
 _getAllParams ()
 Return all parameters in the Request object as an associative array.
 
 _forward ($action, $controller=null, $module=null, array $params=null)
 Forward to another controller/action.
 
 _redirect ($url, array $options=array())
 Redirect to another URL.
 

Protected Attributes

 $_classMethods
 
 $_delimiters
 
 $_invokeArgs = array()
 
 $_frontController
 
 $_request = null
 
 $_response = null
 
 $_helper = null
 

Constructor & Destructor Documentation

__construct ( Zend_Controller_Request_Abstract  $request,
Zend_Controller_Response_Abstract  $response,
array  $invokeArgs = array() 
)

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 getRequest(), getResponse(), and 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 helper broker is initialized.

Finally, init() is called as the final action of instantiation, and may be safely overridden to perform initialization tasks; as a general rule, override init() instead of the constructor to customize an action controller's instantiation.

Parameters
Zend_Controller_Request_Abstract$request
Zend_Controller_Response_Abstract$response
array$invokeArgsAny additional invocation arguments
Returns
void

Implements Zend_Controller_Action_Interface.

Member Function Documentation

__call (   $methodName,
  $args 
)

Proxy for undefined methods.

Default behavior is to throw an exception on undefined methods, however this function can be overridden to implement magic (dynamic) actions, or provide run-time dispatching.

Parameters
string$methodName
array$args
Returns
void
Exceptions
Zend_Controller_Action_Exception
_forward (   $action,
  $controller = null,
  $module = null,
array  $params = null 
)
finalprotected

Forward to another controller/action.

It is important to supply the unformatted names, i.e. "article" rather than "ArticleController". The dispatcher will do the appropriate formatting when the request is received.

If only an action name is provided, forwards to that action in this controller.

If an action and controller are specified, forwards to that action and controller in this module.

Specifying an action, controller, and module is the most specific way to forward.

A fourth argument, $params, will be used to set the request parameters. If either the controller or module are unnecessary for forwarding, simply pass null values for them before specifying the parameters.

Parameters
string$action
string$controller
string$module
array$params
Returns
void
Deprecated:
Deprecated as of Zend Framework 1.7. Use forward() instead.
_getAllParams ( )
protected

Return all parameters in the Request object as an associative array.

Returns
array
Deprecated:
Deprecated as of Zend Framework 1.7. Use getAllParams() instead.
_getParam (   $paramName,
  $default = null 
)
protected

Gets a parameter from the Request object.

If the parameter does not exist, NULL will be returned.

If the parameter does not exist and $default is set, then $default will be returned instead of NULL.

Parameters
string$paramName
mixed$default
Returns
mixed
_hasParam (   $paramName)
protected

Determine whether a given parameter exists in the Request object.

Parameters
string$paramName
Returns
boolean
Deprecated:
Deprecated as of Zend Framework 1.7. Use hasParam() instead.
_redirect (   $url,
array  $options = array() 
)
protected

Redirect to another URL.

Proxies to Zend_Controller_Action_Helper_Redirector::gotoUrl().

Parameters
string$url
array$optionsOptions to be used when redirecting
Returns
void
Deprecated:
Deprecated as of Zend Framework 1.7. Use redirect() instead.
_setInvokeArgs ( array  $args = array())
protected

Set invocation arguments.

Parameters
array$args
Returns
Zend_Controller_Action
_setParam (   $paramName,
  $value 
)
protected

Set a parameter in the Request object.

Parameters
string$paramName
mixed$value
Returns
Zend_Controller_Action
Deprecated:
Deprecated as of Zend Framework 1.7. Use setParam() instead.
dispatch (   $action)

Dispatch the requested action.

Parameters
string$actionMethod name of action
Returns
void

Implements Zend_Controller_Action_Interface.

forward (   $action,
  $controller = null,
  $module = null,
array  $params = null 
)
final

Forward to another controller/action.

It is important to supply the unformatted names, i.e. "article" rather than "ArticleController". The dispatcher will do the appropriate formatting when the request is received.

If only an action name is provided, forwards to that action in this controller.

If an action and controller are specified, forwards to that action and controller in this module.

Specifying an action, controller, and module is the most specific way to forward.

A fourth argument, $params, will be used to set the request parameters. If either the controller or module are unnecessary for forwarding, simply pass null values for them before specifying the parameters.

Parameters
string$action
string$controller
string$module
array$params
Returns
void
getAllParams ( )

Return all parameters in the Request object as an associative array.

Returns
array
getFrontController ( )

Retrieve Front Controller.

Returns
Zend_Controller_Front
getHelper (   $helperName)

Get a helper by name.

Parameters
string$helperName
Returns
Zend_Controller_Action_Helper_Abstract
getHelperCopy (   $helperName)

Get a clone of a helper by name.

Parameters
string$helperName
Returns
Zend_Controller_Action_Helper_Abstract
getInvokeArg (   $key)

Return a single invocation argument.

Parameters
string$key
Returns
mixed
getInvokeArgs ( )

Return the array of constructor arguments (minus the Request object)

Returns
array
getParam (   $paramName,
  $default = null 
)

Gets a parameter from the Request object.

If the parameter does not exist, NULL will be returned.

If the parameter does not exist and $default is set, then $default will be returned instead of NULL.

Parameters
string$paramName
mixed$default
Returns
mixed
getRequest ( )

Return the Request object.

Returns
Zend_Controller_Request_Abstract
getResponse ( )

Return the Response object.

Returns
Zend_Controller_Response_Abstract
getViewScript (   $action = null,
  $noController = null 
)

Construct view script path.

Used by render() to determine the path to the view script.

Parameters
string$actionDefaults to action registered in request object
bool$noControllerDefaults to false; i.e. use controller name as subdir in which to search for view script
Returns
string
Exceptions
Zend_Controller_Exceptionwith bad $action
hasParam (   $paramName)

Determine whether a given parameter exists in the Request object.

Parameters
string$paramName
Returns
boolean
init ( )

Initialize object.

Called from __construct() as final step of object instantiation.

Returns
void
initView ( )

Initialize View object.

Initializes $view if not otherwise a Zend_View_Interface.

If $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/
Returns
Zend_View_Interface
Exceptions
Zend_Controller_Exceptionif base view directory does not exist
postDispatch ( )

Post-dispatch routines.

Called after action method execution. If using class with Zend_Controller_Front, it may modify the Request object and reset its dispatched flag in order to process an additional action.

Common usages for postDispatch() include rendering content in a sitewide template, link url correction, setting headers, etc.

Returns
void
preDispatch ( )

Pre-dispatch routines.

Called before action method. If using class with Zend_Controller_Front, it may modify the Request object and reset its dispatched flag in order to skip processing the current action.

Returns
void
redirect (   $url,
array  $options = array() 
)

Redirect to another URL.

Proxies to Zend_Controller_Action_Helper_Redirector::gotoUrl().

Parameters
string$url
array$optionsOptions to be used when redirecting
Returns
void
render (   $action = null,
  $name = null,
  $noController = false 
)

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 $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 Also
Zend_Controller_Response_Abstract::appendBody()
Parameters
string | null$actionDefaults to action registered in request object
string | null$nameResponse object named path segment to use; defaults to null
bool$noControllerDefaults to false; i.e. use controller name as subdir in which to search for view script
Returns
void
renderScript (   $script,
  $name = null 
)

Render a given view script.

Similar to render(), this method renders a view script. Unlike render(), however, it does not autodetermine the view script via 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.

Parameters
string$script
string$name
Returns
void
run ( Zend_Controller_Request_Abstract  $request = null,
Zend_Controller_Response_Abstract  $response = null 
)

Call the action specified in the request object, and return a response.

Not used in the Action Controller implementation, but left for usage in Page Controller implementations. Dispatches a method based on the request.

Returns a Zend_Controller_Response_Abstract object, instantiating one prior to execution if none exists in the controller.

preDispatch() is called prior to the action, postDispatch() is called following it.

Parameters
null | Zend_Controller_Request_Abstract$requestOptional request object to use
null | Zend_Controller_Response_Abstract$responseOptional response object to use
Returns
Zend_Controller_Response_Abstract
setFrontController ( Zend_Controller_Front  $front)

Set the front controller instance.

Parameters
Zend_Controller_Front$front
Returns
Zend_Controller_Action
setParam (   $paramName,
  $value 
)

Set a parameter in the Request object.

Parameters
string$paramName
mixed$value
Returns
Zend_Controller_Action
setRequest ( Zend_Controller_Request_Abstract  $request)

Set the Request object.

Parameters
Zend_Controller_Request_Abstract$request
Returns
Zend_Controller_Action
setResponse ( Zend_Controller_Response_Abstract  $response)

Set the Response object.

Parameters
Zend_Controller_Response_Abstract$response
Returns
Zend_Controller_Action

Member Data Documentation

$_classMethods
protected
$_delimiters
protected
$_frontController
protected
$_helper = null
protected
$_invokeArgs = array()
protected
$_request = null
protected
$_response = null
protected
$view
$viewSuffix = 'phtml'