Controller/Action.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-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Controller
- Version
- $Id$
\Zend_Controller_Action
Package: Zend_Controller- Implements
- Children
- \Zend_Rest_Controller
- Category
- Zend
- Copyright
- Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties
array $_invokeArgs = array()
Array of arguments provided to the constructor, minus the
{@link $_request Request object}.
Default valuearray()
Details- Type
- array
string $viewSuffix = 'phtml'
View script suffix; defaults to 'phtml'
Default value'phtml'
Details- Type
- string
- See
-
Methods
__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.
ParametersName | Type | Description |
---|
$methodName | string | |
---|
$args | array | |
---|
Throws __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 {@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_forward(string $action, string $controller = null, string $module = null, array $params = null) : void
finalForward 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.
ParametersName | Type | Description |
---|
$action | string | |
---|
$controller | string | |
---|
$module | string | |
---|
$params | array | |
---|
Details- Deprecated
- Deprecated as of Zend Framework 1.7. Use
forward() instead.
_getAllParams() : array
Return all parameters in the {@link $_request Request object}
as an associative array.
ReturnsDetails- Deprecated
- Deprecated as of Zend Framework 1.7. Use
getAllParams() instead.
_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.
If the parameter does not exist and $default is set, then
$default will be returned instead of NULL.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
$default | mixed | |
---|
Returns_hasParam(string $paramName) : boolean
Determine whether a given parameter exists in the
{@link $_request Request object}.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
ReturnsDetails- Deprecated
- Deprecated as of Zend Framework 1.7. Use
hasParam() instead.
_redirect(string $url, array $options = array()) : void
Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
ParametersName | Type | Description |
---|
$url | string | |
---|
$options | array | Options to be used when redirecting |
---|
Details- Deprecated
- Deprecated as of Zend Framework 1.7. Use
redirect() instead.
_setParam(string $paramName, mixed $value) : \Zend_Controller_Action
Set a parameter in the {@link $_request Request object}.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
$value | mixed | |
---|
ReturnsDetails- Deprecated
- Deprecated as of Zend Framework 1.7. Use
setParam() instead.
dispatch(string $action) : void
Dispatch the requested action
ParametersName | Type | Description |
---|
$action | string | Method name of action |
---|
forward(string $action, string $controller = null, string $module = null, array $params = null) : void
finalForward 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.
ParametersName | Type | Description |
---|
$action | string | |
---|
$controller | string | |
---|
$module | string | |
---|
$params | array | |
---|
getInvokeArg(string $key) : mixed
Return a single invocation argument
ParametersName | Type | Description |
---|
$key | string | |
---|
Returns 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.
If the parameter does not exist and $default is set, then
$default will be returned instead of NULL.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
$default | mixed | |
---|
ReturnsgetViewScript(string $action = null, bool $noController = null) : string
Construct view script path
Used by render() to determine the path to the view script.
ParametersName | 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 |
---|
ReturnsThrowshasParam(string $paramName) : boolean
Determine whether a given parameter exists in the
{@link $_request Request object}.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
Returns redirect(string $url, array $options = array()) : void
Proxies to {@link Zend_Controller_Action_Helper_Redirector::gotoUrl()}.
ParametersName | 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
/.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. ParametersName | 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
-
renderScript(string $script, string $name = null) : void
Render a given view script
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.
ParametersName | 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
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.
ParametersReturnssetParam(string $paramName, mixed $value) : \Zend_Controller_Action
Set a parameter in the {@link $_request Request object}.
ParametersName | Type | Description |
---|
$paramName | string | |
---|
$value | mixed | |
---|
Returns