An abstract class to guide implementation of action controllers for use with Zend_Rest_Route.

category Zend
package Zend_Rest
see
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License
inherited_from \Zend_Controller_Action

 Methods

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.

__call(string $methodName, array $args) : void
Inherited

Parameters

$methodName

string

$args

array

Exceptions

\Zend_Controller_Action_Exception

Class constructor

__construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) : void
Inherited

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

inherited_from \Zend_Controller_Action_Interface::__construct()

Parameters

$request

\Zend_Controller_Request_Abstract

$response

\Zend_Controller_Response_Abstract

$invokeArgs

array

Any additional invocation arguments

The delete action handles DELETE requests and receives an 'id' parameter; it should update the server resource state of the resource identified by the 'id' value.

deleteAction() 

Dispatch the requested action

dispatch(string $action) : void
Inherited
inherited_from \Zend_Controller_Action_Interface::dispatch()

Parameters

$action

string

Method name of action

Forward to another controller/action.

forward(string $action, string $controller = null, string $module = null, array $params = null) : void
Inherited

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

$action

string

$controller

string

$module

string

$params

array

The get action handles GET requests and receives an 'id' parameter; it should respond with the server resource state of the resource identified by the 'id' value.

getAction() 

Return all parameters in the {@link $_request Request object} as an associative array.

getAllParams() : array
Inherited

Returns

array

Retrieve Front Controller

getFrontController() : \Zend_Controller_Front
Inherited

Returns

\Zend_Controller_Front

Get a helper by name

getHelper(string $helperName) : \Zend_Controller_Action_Helper_Abstract
Inherited

Parameters

$helperName

string

Returns

\Zend_Controller_Action_Helper_Abstract

Get a clone of a helper by name

getHelperCopy(string $helperName) : \Zend_Controller_Action_Helper_Abstract
Inherited

Parameters

$helperName

string

Returns

\Zend_Controller_Action_Helper_Abstract

Return a single invocation argument

getInvokeArg(string $key) : mixed
Inherited

Parameters

$key

string

Returns

mixed

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

getInvokeArgs() : array
Inherited

Returns

array

Gets a parameter from the {@link $_request Request object}. If the parameter does not exist, NULL will be returned.

getParam(string $paramName, mixed $default = null) : mixed
Inherited

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

Parameters

$paramName

string

$default

mixed

Returns

mixed

Return the Request object

getRequest() : \Zend_Controller_Request_Abstract
Inherited

Returns

\Zend_Controller_Request_Abstract

Return the Response object

getResponse() : \Zend_Controller_Response_Abstract
Inherited

Returns

\Zend_Controller_Response_Abstract

Construct view script path

getViewScript(string $action = null, boolean $noController = null) : string
Inherited

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

Parameters

$action

string

Defaults to action registered in request object

$noController

boolean

Defaults to false; i.e. use controller name as subdir in which to search for view script

Exceptions

\Zend_Controller_Exception with bad $action

Returns

string

Determine whether a given parameter exists in the {@link $_request Request object}.

hasParam(string $paramName) : boolean
Inherited

Parameters

$paramName

string

Returns

boolean

The head action handles HEAD requests and receives an 'id' parameter; it should respond with the server resource state of the resource identified by the 'id' value.

headAction() 

The index action handles index/list requests; it should respond with a list of the requested resources.

indexAction() 

Initialize object

init() : void
Inherited

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

Initialize View object

initView() : \Zend_View_Interface
Inherited

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/

Exceptions

\Zend_Controller_Exception if base view directory does not exist

Returns

\Zend_View_Interface

The post action handles POST requests; it should accept and digest a POSTed resource representation and persist the resource state.

postAction() 

Post-dispatch routines

postDispatch() : void
Inherited

Called after action method execution. If using class with Zend_Controller_Front, it may modify the \$_request 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.

Pre-dispatch routines

preDispatch() : void
Inherited

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

The put action handles PUT requests and receives an 'id' parameter; it should update the server resource state of the resource identified by the 'id' value.

putAction() 

Redirect to another URL

redirect(string $url, array $options = array()) : void
Inherited

Parameters

$url

string

$options

array

Options to be used when redirecting

Render a view

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

Renders a view. By default, views are found in the view script path as

/.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

Parameters

$action

stringnull

Defaults to action registered in request object

$name

stringnull

Response object named path segment to use; defaults to null

$noController

boolean

Defaults to false; i.e. use controller name as subdir in which to search for view script

Render a given view script

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

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

$script

string

$name

string

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

run(null|\Zend_Controller_Request_Abstract $request = null, null|\Zend_Controller_Response_Abstract $response = null) : \Zend_Controller_Response_Abstract
Inherited

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

$request

null\Zend_Controller_Request_Abstract

Optional request object to use

$response

null\Zend_Controller_Response_Abstract

Optional response object to use

Returns

\Zend_Controller_Response_Abstract

Set the front controller instance

setFrontController(\Zend_Controller_Front $front) : \Zend_Controller_Action
Inherited

Parameters

$front

\Zend_Controller_Front

Returns

\Zend_Controller_Action

Set a parameter in the {@link $_request Request object}.

setParam(string $paramName, mixed $value) : \Zend_Controller_Action
Inherited

Parameters

$paramName

string

$value

mixed

Returns

\Zend_Controller_Action

Set the Request object

setRequest(\Zend_Controller_Request_Abstract $request) : \Zend_Controller_Action
Inherited

Parameters

$request

\Zend_Controller_Request_Abstract

Returns

\Zend_Controller_Action

Set the Response object

setResponse(\Zend_Controller_Response_Abstract $response) : \Zend_Controller_Action
Inherited

Parameters

$response

\Zend_Controller_Response_Abstract

Returns

\Zend_Controller_Action

Forward to another controller/action.

_forward(string $action, string $controller = null, string $module = null, array $params = null) : void
Inherited

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.

deprecated Deprecated as of Zend Framework 1.7. Use forward() instead.

Parameters

$action

string

$controller

string

$module

string

$params

array

Return all parameters in the {@link $_request Request object} as an associative array.

_getAllParams() : array
Inherited
deprecated Deprecated as of Zend Framework 1.7. Use getAllParams() instead.

Returns

array

Gets a parameter from the {@link $_request Request object}. If the parameter does not exist, NULL will be returned.

_getParam(string $paramName, mixed $default = null) : mixed
Inherited

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

Parameters

$paramName

string

$default

mixed

Returns

mixed

Determine whether a given parameter exists in the {@link $_request Request object}.

_hasParam(string $paramName) : boolean
Inherited
deprecated Deprecated as of Zend Framework 1.7. Use hasParam() instead.

Parameters

$paramName

string

Returns

boolean

Redirect to another URL

_redirect(string $url, array $options = array()) : void
Inherited
deprecated Deprecated as of Zend Framework 1.7. Use redirect() instead.

Parameters

$url

string

$options

array

Options to be used when redirecting

Set invocation arguments

_setInvokeArgs(array $args = array()) : \Zend_Controller_Action
Inherited

Parameters

$args

array

Returns

\Zend_Controller_Action

Set a parameter in the {@link $_request Request object}.

_setParam(string $paramName, mixed $value) : \Zend_Controller_Action
Inherited
deprecated Deprecated as of Zend Framework 1.7. Use setParam() instead.

Parameters

$paramName

string

$value

mixed

Returns

\Zend_Controller_Action

 Properties

 

View object

$view : \Zend_View_Interface

Default

 

View script suffix; defaults to 'phtml'

$viewSuffix : string

Default

'phtml'
see
 

of existing class methods

$_classMethods : array

Default

 

Word delimiters (used for normalizing view script paths)

$_delimiters : array

Default

 

Front controller instance

$_frontController : \Zend_Controller_Front

Default

 

Helper Broker to assist in routing help requests to the proper object

$_helper : \Zend_Controller_Action_HelperBroker

Default

null
 

Array of arguments provided to the constructor, minus the {@link $_request Request object}.

$_invokeArgs : array

Default

array()
 

Zend_Controller_Request_Abstract object wrapping the request environment

$_request : \Zend_Controller_Request_Abstract

Default

null
 

Zend_Controller_Response_Abstract object wrapping the response

$_response : \Zend_Controller_Response_Abstract

Default

null