Rest/Controller.php
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 [email protected] 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_Rest
- Version
- $Id: Controller.php 25024 2012-07-30 15:08:15Z rob $
\Zend_Rest_Controller
An abstract class to guide implementation of action controllers for use with Zend_Rest_Route.
- Parent(s)
- \Zend_Controller_Action
- See
- \global\Zend_Rest_Route
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties


array $_classMethods =
- Type
- array
- Inherited_from
- \Zend_Controller_Action::$$_classMethods


array $_delimiters =
Word delimiters (used for normalizing view script paths)
Inherited from: \Zend_Controller_Action::$$_delimiters- Type
- array
- Inherited_from
- \Zend_Controller_Action::$$_delimiters


\Zend_Controller_Front $_frontController =
- Type
- \Zend_Controller_Front
- Inherited_from
- \Zend_Controller_Action::$$_frontController


\Zend_Controller_Action_HelperBroker $_helper = null
Helper Broker to assist in routing help requests to the proper object
Inherited from: \Zend_Controller_Action::$$_helpernull
Details- Type
- \Zend_Controller_Action_HelperBroker
- Inherited_from
- \Zend_Controller_Action::$$_helper


array $_invokeArgs = array()
Array of arguments provided to the constructor, minus the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::$$_invokeArgsarray()
Details- Type
- array
- Inherited_from
- \Zend_Controller_Action::$$_invokeArgs


\Zend_Controller_Request_Abstract $_request = null
Zend_Controller_Request_Abstract object wrapping the request environment
Inherited from: \Zend_Controller_Action::$$_requestnull
Details- Type
- \Zend_Controller_Request_Abstract
- Inherited_from
- \Zend_Controller_Action::$$_request


\Zend_Controller_Response_Abstract $_response = null
Zend_Controller_Response_Abstract object wrapping the response
Inherited from: \Zend_Controller_Action::$$_responsenull
Details- Type
- \Zend_Controller_Response_Abstract
- Inherited_from
- \Zend_Controller_Action::$$_response


\Zend_View_Interface $view =
- Type
- \Zend_View_Interface
- Inherited_from
- \Zend_Controller_Action::$$view


string $viewSuffix = 'phtml'
View script suffix; defaults to 'phtml'
Inherited from: \Zend_Controller_Action::$$viewSuffix'phtml'
Details- Type
- string
- Inherited_from
- \Zend_Controller_Action::$$viewSuffix
- See
- \global\{render()}
Methods


__call(string $methodName, array $args) : void
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.
Name | Type | Description |
---|---|---|
$methodName | string | |
$args | array |
Exception | Description |
---|---|
\Zend_Controller_Action_Exception |


__construct(\Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array()) : void
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.
Name | Type | Description |
---|---|---|
$request | \Zend_Controller_Request_Abstract | |
$response | \Zend_Controller_Response_Abstract | |
$invokeArgs | array | Any additional invocation arguments |


_forward(string $action, string $controller = null, string $module = null, array $params = null) : void
Forward to another controller/action.
Inherited from: \Zend_Controller_Action::_forward()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.
Name | Type | Description |
---|---|---|
$action | string | |
$controller | string | |
$module | string | |
$params | array |


_getAllParams() : array
Return all parameters in the {@link $_request Request object} as an associative array.
Inherited from: \Zend_Controller_Action::_getAllParams()Type | Description |
---|---|
array |


_getParam(string $paramName, mixed $default = null) : mixed
Gets a parameter from the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::_getParam()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.
Name | Type | Description |
---|---|---|
$paramName | string | |
$default | mixed |
Type | Description |
---|---|
mixed |


_hasParam(string $paramName) : boolean
Determine whether a given parameter exists in the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::_hasParam()Name | Type | Description |
---|---|---|
$paramName | string |
Type | Description |
---|---|
boolean |


_redirect(string $url, array $options = array()) : void
Name | Type | Description |
---|---|---|
$url | string | |
$options | array | Options to be used when redirecting |


_setInvokeArgs(array $args = array()) : \Zend_Controller_Action
Name | Type | Description |
---|---|---|
$args | array |
Type | Description |
---|---|
\Zend_Controller_Action |


_setParam(string $paramName, mixed $value) : \Zend_Controller_Action
Set a parameter in the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::_setParam()Name | Type | Description |
---|---|---|
$paramName | string | |
$value | mixed |
Type | Description |
---|---|
\Zend_Controller_Action |


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


dispatch(string $action) : void
Name | Type | Description |
---|---|---|
$action | string | Method name of action |


forward(string $action, string $controller = null, string $module = null, array $params = null) : void
Forward to another controller/action.
Inherited from: \Zend_Controller_Action::forward()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.
Name | Type | Description |
---|---|---|
$action | string | |
$controller | string | |
$module | string | |
$params | array |


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


getAllParams() : array
Return all parameters in the {@link $_request Request object} as an associative array.
Inherited from: \Zend_Controller_Action::getAllParams()Type | Description |
---|---|
array |


getHelper(string $helperName) : \Zend_Controller_Action_Helper_Abstract
Name | Type | Description |
---|---|---|
$helperName | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_Abstract |


getHelperCopy(string $helperName) : \Zend_Controller_Action_Helper_Abstract
Name | Type | Description |
---|---|---|
$helperName | string |
Type | Description |
---|---|
\Zend_Controller_Action_Helper_Abstract |


getInvokeArg(string $key) : mixed
Return a single invocation argument
Inherited from: \Zend_Controller_Action::getInvokeArg()Name | Type | Description |
---|---|---|
$key | string |
Type | Description |
---|---|
mixed |


getInvokeArgs() : array
Return the array of constructor arguments (minus the Request object)
Inherited from: \Zend_Controller_Action::getInvokeArgs()Type | Description |
---|---|
array |


getParam(string $paramName, mixed $default = null) : mixed
Gets a parameter from the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::getParam()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.
Name | Type | Description |
---|---|---|
$paramName | string | |
$default | mixed |
Type | Description |
---|---|
mixed |


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


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


getViewScript(string $action = null, bool $noController = null) : string
Used by render() to determine the path to the view script.
Name | Type | Description |
---|---|---|
$action | string | Defaults to action registered in request object |
$noController | bool | Defaults to false; i.e. use controller name as subdir in which to search for view script |
Type | Description |
---|---|
string |
Exception | Description |
---|---|
\Zend_Controller_Exception | with bad $action |


hasParam(string $paramName) : boolean
Determine whether a given parameter exists in the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::hasParam()Name | Type | Description |
---|---|---|
$paramName | string |
Type | Description |
---|---|
boolean |


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


indexAction() : void
The index action handles index/list requests; it should respond with a list of the requested resources.


initView() : \Zend_View_Interface
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/
Type | Description |
---|---|
\Zend_View_Interface |
Exception | Description |
---|---|
\Zend_Controller_Exception | if base view directory does not exist |


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


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


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


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


redirect(string $url, array $options = array()) : void
Name | Type | Description |
---|---|---|
$url | string | |
$options | array | Options to be used when redirecting |


render(string | null $action = null, string | null $name = null, bool $noController = false) : void
Renders a view. By default, views are found in the view script path as
By default, the rendered contents are appended to the response. You may specify the named body content segment to set by specifying a $name.
Name | Type | Description |
---|---|---|
$action | string | null | Defaults to action registered in request object |
$name | string | null | Response object named path segment to use; defaults to null |
$noController | bool | Defaults to false; i.e. use controller name as subdir in which to search for view script |
- See
- \global\Zend_Controller_Response_Abstract::appendBody()


renderScript(string $script, string $name = null) : void
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.
Name | Type | Description |
---|---|---|
$script | string | |
$name | string |


run(null | \Zend_Controller_Request_Abstract $request = null, null | \Zend_Controller_Response_Abstract $response = null) : \Zend_Controller_Response_Abstract
Call the action specified in the request object, and return a response
Inherited from: \Zend_Controller_Action::run()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.
Name | Type | Description |
---|---|---|
$request | null | \Zend_Controller_Request_Abstract | Optional request object to use |
$response | null | \Zend_Controller_Response_Abstract | Optional response object to use |
Type | Description |
---|---|
\Zend_Controller_Response_Abstract |


setFrontController(\Zend_Controller_Front $front) : \Zend_Controller_Action
Set the front controller instance
Inherited from: \Zend_Controller_Action::setFrontController()Name | Type | Description |
---|---|---|
$front | \Zend_Controller_Front |
Type | Description |
---|---|
\Zend_Controller_Action |


setParam(string $paramName, mixed $value) : \Zend_Controller_Action
Set a parameter in the {@link $_request Request object}.
Inherited from: \Zend_Controller_Action::setParam()Name | Type | Description |
---|---|---|
$paramName | string | |
$value | mixed |
Type | Description |
---|---|
\Zend_Controller_Action |


setRequest(\Zend_Controller_Request_Abstract $request) : \Zend_Controller_Action
Name | Type | Description |
---|---|---|
$request | \Zend_Controller_Request_Abstract |
Type | Description |
---|---|
\Zend_Controller_Action |


setResponse(\Zend_Controller_Response_Abstract $response) : \Zend_Controller_Action
Name | Type | Description |
---|---|---|
$response | \Zend_Controller_Response_Abstract |
Type | Description |
---|---|
\Zend_Controller_Action |