API Documentation

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 license@zend.com so we can send you a copy immediately.

category
Zend  
copyright
Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)  
license
New BSD License  
package
Zend_Rest  
version
$Id: Controller.php 23953 2011-05-03 05:47:39Z ralph $  

\Zend_Rest_Controller

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

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

Methods

methodpublic__call( string $methodName, array $args ) : void

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.

Inherited from: \Zend_Controller_Action::__call()
Parameters
Name Type Description
$methodName string
$args array
Throws
Exception Description
\Zend_Controller_Action_Exception
methodpublic__construct( \Zend_Controller_Request_Abstract $request, \Zend_Controller_Response_Abstract $response, array $invokeArgs = array ) : void

Class constructor

Inherited from: \Zend_Controller_Action::__construct()

The request and response objects should be registered with the controller, as should be any additional optional arguments; these will be available via {@link getRequest()}, {@link getResponse()}, and {@link 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 {@link $_helper helper broker} is initialized.

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

Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract
$response \Zend_Controller_Response_Abstract
$invokeArgs array Any additional invocation arguments
methodprotected_forward( string $action, string $controller = null, string $module = null, array $params = null ) : void
final

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.

Parameters
Name Type Description
$action string
$controller string
$module string
$params array
methodprotected_getAllParams( ) : array

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

Inherited from: \Zend_Controller_Action::_getAllParams()
Returns
Type Description
array
methodprotected_getParam( string $paramName, mixed $default = null ) : mixed

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

Inherited from: \Zend_Controller_Action::_getParam()

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

Parameters
Name Type Description
$paramName string
$default mixed
Returns
Type Description
mixed
methodprotected_hasParam( string $paramName ) : boolean

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

Inherited from: \Zend_Controller_Action::_hasParam()
Parameters
Name Type Description
$paramName string
Returns
Type Description
boolean
methodprotected_redirect( string $url, array $options = array ) : void

Redirect to another URL

Inherited from: \Zend_Controller_Action::_redirect()

Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.

Parameters
Name Type Description
$url string
$options array Options to be used when redirecting
methodprotected_setInvokeArgs( array $args = array ) : \Zend_Controller_Action

Set invocation arguments

Inherited from: \Zend_Controller_Action::_setInvokeArgs()
Parameters
Name Type Description
$args array
Returns
Type Description
\Zend_Controller_Action
methodprotected_setParam( string $paramName, mixed $value ) : \Zend_Controller_Action

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

Inherited from: \Zend_Controller_Action::_setParam()
Parameters
Name Type Description
$paramName string
$value mixed
Returns
Type Description
\Zend_Controller_Action
methodpublicdeleteAction( ) : void
abstract

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.

methodpublicdispatch( string $action ) : void

Dispatch the requested action

Inherited from: \Zend_Controller_Action::dispatch()
Parameters
Name Type Description
$action string Method name of action
methodpublicgetAction( ) : void
abstract

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.

methodpublicgetFrontController( ) : \Zend_Controller_Front

Retrieve Front Controller

Inherited from: \Zend_Controller_Action::getFrontController()
Returns
Type Description
\Zend_Controller_Front
methodpublicgetHelper( string $helperName ) : \Zend_Controller_Action_Helper_Abstract

Get a helper by name

Inherited from: \Zend_Controller_Action::getHelper()
Parameters
Name Type Description
$helperName string
Returns
Type Description
\Zend_Controller_Action_Helper_Abstract
methodpublicgetHelperCopy( string $helperName ) : \Zend_Controller_Action_Helper_Abstract

Get a clone of a helper by name

Inherited from: \Zend_Controller_Action::getHelperCopy()
Parameters
Name Type Description
$helperName string
Returns
Type Description
\Zend_Controller_Action_Helper_Abstract
methodpublicgetInvokeArg( string $key ) : mixed

Return a single invocation argument

Inherited from: \Zend_Controller_Action::getInvokeArg()
Parameters
Name Type Description
$key string
Returns
Type Description
mixed
methodpublicgetInvokeArgs( ) : array

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

Inherited from: \Zend_Controller_Action::getInvokeArgs()
Returns
Type Description
array
methodpublicgetRequest( ) : \Zend_Controller_Request_Abstract

Return the Request object

Inherited from: \Zend_Controller_Action::getRequest()
Returns
Type Description
\Zend_Controller_Request_Abstract
methodpublicgetResponse( ) : \Zend_Controller_Response_Abstract

Return the Response object

Inherited from: \Zend_Controller_Action::getResponse()
Returns
Type Description
\Zend_Controller_Response_Abstract
methodpublicgetViewScript( string $action = null, bool $noController = null ) : string

Construct view script path

Inherited from: \Zend_Controller_Action::getViewScript()

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

Parameters
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
Returns
Type Description
string
Throws
Exception Description
\Zend_Controller_Exception with bad $action
methodpublicindexAction( ) : void
abstract

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

methodpublicinit( ) : void

Initialize object

Inherited from: \Zend_Controller_Action::init()

Called from {@link __construct()} as final step of object instantiation.

methodpublicinitView( ) : \Zend_View_Interface

Initialize View object

Inherited from: \Zend_Controller_Action::initView()

Initializes {@link $view} if not otherwise a Zend_View_Interface.

If {@link $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
Type Description
\Zend_View_Interface
Throws
Exception Description
\Zend_Controller_Exception if base view directory does not exist
methodpublicpostAction( ) : void
abstract

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

methodpublicpostDispatch( ) : void

Post-dispatch routines

Inherited from: \Zend_Controller_Action::postDispatch()

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

methodpublicpreDispatch( ) : void

Pre-dispatch routines

Inherited from: \Zend_Controller_Action::preDispatch()

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

methodpublicputAction( ) : void
abstract

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.

methodpublicrender( string|null $action = null, string|null $name = null, bool $noController = false ) : void

Render a view

Inherited from: \Zend_Controller_Action::render()

Renders a view. By default, views are found in the view script path as /.phtml. You may change the script suffix by resetting {@link $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.

Parameters
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
Details
see
\Zend_Controller_Response_Abstract::appendBody()  
methodpublicrenderScript( string $script, string $name = null ) : void

Render a given view script

Inherited from: \Zend_Controller_Action::renderScript()

Similar to {@link render()}, this method renders a view script. Unlike render(), however, it does not autodetermine the view script via {@link 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
Name Type Description
$script string
$name string
methodpublicrun( 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.

{@link preDispatch()} is called prior to the action, {@link postDispatch()} is called following it.

Parameters
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
Returns
Type Description
\Zend_Controller_Response_Abstract
methodpublicsetFrontController( \Zend_Controller_Front $front ) : \Zend_Controller_Action

Set the front controller instance

Inherited from: \Zend_Controller_Action::setFrontController()
Parameters
Name Type Description
$front \Zend_Controller_Front
Returns
Type Description
\Zend_Controller_Action
methodpublicsetRequest( \Zend_Controller_Request_Abstract $request ) : \Zend_Controller_Action

Set the Request object

Inherited from: \Zend_Controller_Action::setRequest()
Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract
Returns
Type Description
\Zend_Controller_Action
methodpublicsetResponse( \Zend_Controller_Response_Abstract $response ) : \Zend_Controller_Action

Set the Response object

Inherited from: \Zend_Controller_Action::setResponse()
Parameters
Name Type Description
$response \Zend_Controller_Response_Abstract
Returns
Type Description
\Zend_Controller_Action
Documentation was generated by DocBlox 0.13.3.