Controller/Front.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_Controller
- Version
- $Id: Front.php 24593 2012-01-05 20:35:02Z matthew $
\Zend_Controller_Front
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties


string|array $_controllerDir = null
Directory|ies where controllers are stored
null
Details- Type
- string | array


\Zend_Controller_Dispatcher_Interface $_dispatcher = null
Instance of Zend_Controller_Dispatcher_Interface
null
Details


\Zend_Controller_Front $_instance = null
Singleton instance
Marked only as protected to allow extension of the class. To extend, simply override getInstance().
null
Details


array $_invokeParams = array()
Array of invocation parameters to use when instantiating action controllers
array()
Details- Type
- array


string $_moduleControllerDirectoryName = 'controllers'
Subdirectory within a module containing controllers; defaults to 'controllers'
'controllers'
Details- Type
- string


\Zend_Controller_Plugin_Broker $_plugins = null
Instance of Zend_Controller_Plugin_Broker
null
Details


\Zend_Controller_Request_Abstract $_request = null
Instance of Zend_Controller_Request_Abstract
null
Details


\Zend_Controller_Response_Abstract $_response = null
Instance of Zend_Controller_Response_Abstract
null
Details


boolean $_returnResponse = false
Whether or not to return the response prior to rendering output while in {@link dispatch()}; default is to send headers and render output.
false
Details- Type
- boolean


\Zend_Controller_Router_Interface $_router = null
Instance of Zend_Controller_Router_Interface
null
Details
Methods


__construct() : void
Constructor
Instantiate using getInstance(); front controller is a singleton object.
Instantiates the plugin broker.


addControllerDirectory(string $directory, string $module = null) : \Zend_Controller_Front
Add a controller directory to the controller directory stack
If $args is presented and is a string, uses it for the array key mapping to the directory specified.
Name | Type | Description |
---|---|---|
$directory | string | |
$module | string | Optional argument; module with which to associate directory. If none provided, assumes 'default' |
Type | Description |
---|---|
\Zend_Controller_Front |
Exception | Description |
---|---|
\Zend_Controller_Exception | if directory not found or readable |


addModuleDirectory(string $path) : \Zend_Controller_Front
Specify a directory as containing modules
Iterates through the directory, adding any subdirectories as modules; the subdirectory within each module named after $_moduleControllerDirectoryName will be used as the controller directory path.
Name | Type | Description |
---|---|---|
$path | string |
Type | Description |
---|---|
\Zend_Controller_Front |


clearParams(null | string | array $name = null) : \Zend_Controller_Front
Clear the controller parameter stack
By default, clears all parameters. If a parameter name is given, clears only that parameter; if an array of parameter names is provided, clears each.
Name | Type | Description |
---|---|---|
$name | null | string | array | single key or array of keys for params to clear |
Type | Description |
---|---|
\Zend_Controller_Front |


dispatch(\Zend_Controller_Request_Abstract | null $request = null, \Zend_Controller_Response_Abstract | null $response = null) : void | \Zend_Controller_Response_Abstract
Dispatch an HTTP request to a controller/action.
Name | Type | Description |
---|---|---|
$request | \Zend_Controller_Request_Abstract | null | |
$response | \Zend_Controller_Response_Abstract | null |
Type | Description |
---|---|
void | \Zend_Controller_Response_Abstract | Returns response object if returnResponse() is true |


getControllerDirectory(string $name = null) : array | string | null
Retrieve controller directory
Retrieves: - Array of all controller directories if no $name passed - String path if $name passed and exists as a key in controller directory array - null if $name passed but does not exist in controller directory keys
Name | Type | Description |
---|---|---|
$name | string | Default null |
Type | Description |
---|---|
array | string | null |


getDefaultAction() : string
Retrieve the default action (unformatted string)
Type | Description |
---|---|
string |


getDefaultControllerName() : string
Retrieve the default controller (unformatted string)
Type | Description |
---|---|
string |


getDispatcher() : \Zend_Controller_Dispatcher_Interface
Return the dispatcher object.
Type | Description |
---|---|
\Zend_Controller_Dispatcher_Interface |


getInstance() : \Zend_Controller_Front
Singleton instance
Type | Description |
---|---|
\Zend_Controller_Front |


getModuleControllerDirectoryName() : string
Return the directory name within a module containing controllers
Type | Description |
---|---|
string |


getModuleDirectory(string $module = null) : string | null
Return the path to a module directory (but not the controllers directory within)
Name | Type | Description |
---|---|---|
$module | string |
Type | Description |
---|---|
string | null |


getParam(string $name) : mixed
Retrieve a single parameter from the controller parameter stack
Name | Type | Description |
---|---|---|
$name | string |
Type | Description |
---|---|
mixed |


getParams() : array
Retrieve action controller instantiation parameters
Type | Description |
---|---|
array |


getPlugin(string $class) : false | \Zend_Controller_Plugin_Abstract | array
Retrieve a plugin or plugins by class
Name | Type | Description |
---|---|---|
$class | string |
Type | Description |
---|---|
false | \Zend_Controller_Plugin_Abstract | array |


getRequest() : null | \Zend_Controller_Request_Abstract
Return the request object.
Type | Description |
---|---|
null | \Zend_Controller_Request_Abstract |


getResponse() : null | \Zend_Controller_Response_Abstract
Return the response object.
Type | Description |
---|---|
null | \Zend_Controller_Response_Abstract |


getRouter() : \Zend_Controller_Router_Interface
Return the router object.
Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.
Type | Description |
---|---|
\Zend_Controller_Router_Interface |


hasPlugin(string $class) : bool
Is a particular plugin registered?
Name | Type | Description |
---|---|---|
$class | string |
Type | Description |
---|---|
bool |


registerPlugin(\Zend_Controller_Plugin_Abstract $plugin, int $stackIndex = null) : \Zend_Controller_Front
Register a plugin.
Name | Type | Description |
---|---|---|
$plugin | \Zend_Controller_Plugin_Abstract | |
$stackIndex | int | Optional; stack index for plugin |
Type | Description |
---|---|
\Zend_Controller_Front |


removeControllerDirectory(string $module) : bool
Remove a controller directory by module name
Name | Type | Description |
---|---|---|
$module | string |
Type | Description |
---|---|
bool |


resetInstance() : void
Resets all object properties of the singleton instance
Primarily used for testing; could be used to chain front controllers.
Also resets action helper broker, clearing all registered helpers.


returnResponse(boolean $flag = null) : boolean | \Zend_Controller_Front
Set whether {@link dispatch()} should return the response without first rendering output.
By default, output is rendered and dispatch() returns nothing.
Name | Type | Description |
---|---|---|
$flag | boolean |
Type | Description |
---|---|
boolean | \Zend_Controller_Front | Used as a setter, returns object; as a getter, returns boolean |


run(string | array $controllerDirectory) : void
Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()
In PHP 5.1.x, a call to a static method never populates $this -- so run() may actually be called after setting up your front controller.
Name | Type | Description |
---|---|---|
$controllerDirectory | string | array | Path to Zend_Controller_Action controller classes or array of such paths |
Exception | Description |
---|---|
\Zend_Controller_Exception | if called from an object instance |


setBaseUrl(string $base = null) : \Zend_Controller_Front
Set the base URL used for requests
Use to set the base URL segment of the REQUEST_URI to use when determining PATH_INFO, etc. Examples: - /admin - /myapp - /subdir/index.php
Note that the URL should not include the full URI. Do not use: - http://example.com/admin - http://example.com/myapp - http://example.com/subdir/index.php
If a null value is passed, this can be used as well for autodiscovery (default).
Name | Type | Description |
---|---|---|
$base | string |
Type | Description |
---|---|
\Zend_Controller_Front |
Exception | Description |
---|---|
\Zend_Controller_Exception | for non-string $base |


setControllerDirectory(string | array $directory, string $module = null) : \Zend_Controller_Front
Set controller directory
Stores controller directory(ies) in dispatcher. May be an array of directories or a string containing a single directory.
Name | Type | Description |
---|---|---|
$directory | string | array | Path to Zend_Controller_Action controller classes or array of such paths |
$module | string | Optional module name to use with string $directory |
Type | Description |
---|---|
\Zend_Controller_Front |


setDefaultAction(string $action) : \Zend_Controller_Front
Set the default action (unformatted string)
Name | Type | Description |
---|---|---|
$action | string |
Type | Description |
---|---|
\Zend_Controller_Front |


setDefaultControllerName(string $controller) : \Zend_Controller_Front
Set the default controller (unformatted string)
Name | Type | Description |
---|---|---|
$controller | string |
Type | Description |
---|---|
\Zend_Controller_Front |


setDefaultModule(string $module) : \Zend_Controller_Front
Set the default module name
Name | Type | Description |
---|---|---|
$module | string |
Type | Description |
---|---|
\Zend_Controller_Front |


setDispatcher(\Zend_Controller_Dispatcher_Interface $dispatcher) : \Zend_Controller_Front
Set the dispatcher object.
The dispatcher is responsible for taking a Zend_Controller_Dispatcher_Token object, instantiating the controller, and call the action method of the controller.
Name | Type | Description |
---|---|---|
$dispatcher | \Zend_Controller_Dispatcher_Interface |
Type | Description |
---|---|
\Zend_Controller_Front |


setModuleControllerDirectoryName(string $name = 'controllers') : \Zend_Controller_Front
Set the directory name within a module containing controllers
Name | Type | Description |
---|---|---|
$name | string |
Type | Description |
---|---|
\Zend_Controller_Front |


setParam(string $name, mixed $value) : \Zend_Controller_Front
Add or modify a parameter to use when instantiating an action controller
Name | Type | Description |
---|---|---|
$name | string | |
$value | mixed |
Type | Description |
---|---|
\Zend_Controller_Front |


setParams(array $params) : \Zend_Controller_Front
Set parameters to pass to action controller constructors
Name | Type | Description |
---|---|---|
$params | array |
Type | Description |
---|---|
\Zend_Controller_Front |


setRequest(string | \Zend_Controller_Request_Abstract $request) : \Zend_Controller_Front
Set request class/object
Set the request object. The request holds the request environment.
If a class name is provided, it will instantiate it
Name | Type | Description |
---|---|---|
$request | string | \Zend_Controller_Request_Abstract |
Type | Description |
---|---|
\Zend_Controller_Front |
Exception | Description |
---|---|
\Zend_Controller_Exception | if invalid request class |


setResponse(string | \Zend_Controller_Response_Abstract $response) : \Zend_Controller_Front
Set response class/object
Set the response object. The response is a container for action responses and headers. Usage is optional.
If a class name is provided, instantiates a response object.
Name | Type | Description |
---|---|---|
$response | string | \Zend_Controller_Response_Abstract |
Type | Description |
---|---|
\Zend_Controller_Front |
Exception | Description |
---|---|
\Zend_Controller_Exception | if invalid response class |


setRouter(string | \Zend_Controller_Router_Interface $router) : \Zend_Controller_Front
Set router class/object
Set the router object. The router is responsible for mapping the request to a controller and action.
If a class name is provided, instantiates router with any parameters registered via setParam() or setParams().
Name | Type | Description |
---|---|---|
$router | string | \Zend_Controller_Router_Interface |
Type | Description |
---|---|
\Zend_Controller_Front |
Exception | Description |
---|---|
\Zend_Controller_Exception | if invalid router class |


throwExceptions(boolean $flag = null) : boolean | \Zend_Controller_Front
Set the throwExceptions flag and retrieve current status
Set whether exceptions encounted in the dispatch loop should be thrown or caught and trapped in the response object.
Default behaviour is to trap them in the response object; call this method to have them thrown.
Passing no value will return the current value of the flag; passing a boolean true or false value will set the flag and return the current object instance.
Name | Type | Description |
---|---|---|
$flag | boolean | Defaults to null (return flag state) |
Type | Description |
---|---|
boolean | \Zend_Controller_Front | Used as a setter, returns object; as a getter, returns boolean |


unregisterPlugin(string | \Zend_Controller_Plugin_Abstract $plugin) : \Zend_Controller_Front
Unregister a plugin.
Name | Type | Description |
---|---|---|
$plugin | string | \Zend_Controller_Plugin_Abstract | Plugin class or object to unregister |
Type | Description |
---|---|
\Zend_Controller_Front |