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

 Methods

Add a controller directory to the controller directory stack

addControllerDirectory(string $directory, string $module = null) : \Zend_Controller_Front

If $args is presented and is a string, uses it for the array key mapping to the directory specified.

Parameters

$directory

string

$module

string

Optional argument; module with which to associate directory. If none provided, assumes 'default'

Exceptions

\Zend_Controller_Exception if directory not found or readable

Returns

\Zend_Controller_Front

Specify a directory as containing modules

addModuleDirectory(string $path) : \Zend_Controller_Front

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.

Parameters

$path

string

Returns

\Zend_Controller_Front

Clear the controller parameter stack

clearParams($name = null) : \Zend_Controller_Front

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.

Parameters

$name

Returns

\Zend_Controller_Front

Dispatch an HTTP request to a controller/action.

dispatch(\Zend_Controller_Request_Abstract|null $request = null, \Zend_Controller_Response_Abstract|null $response = null) : void | \Zend_Controller_Response_Abstract

Parameters

$request

\Zend_Controller_Request_Abstractnull

$response

\Zend_Controller_Response_Abstractnull

Returns

void\Zend_Controller_Response_AbstractReturns response object if returnResponse() is true

Retrieve the currently set base URL

getBaseUrl() : string

Returns

string

Retrieve controller directory

getControllerDirectory(string $name = null) : array | string | null

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

Parameters

$name

string

Default null

Returns

arraystringnull

Retrieve the default action (unformatted string)

getDefaultAction() : string

Returns

string

Retrieve the default controller (unformatted string)

getDefaultControllerName() : string

Returns

string

Retrieve the default module

getDefaultModule() : string

Returns

string

Return the dispatcher object.

getDispatcher() : \Zend_Controller_Dispatcher_Interface

Returns

\Zend_Controller_Dispatcher_Interface

Singleton instance

getInstance() : \Zend_Controller_Front
Static

Returns

\Zend_Controller_Front

Return the directory name within a module containing controllers

getModuleControllerDirectoryName() : string

Returns

string

Return the path to a module directory (but not the controllers directory within)

getModuleDirectory(string $module = null) : string | null

Parameters

$module

string

Returns

stringnull

Retrieve a single parameter from the controller parameter stack

getParam(string $name) : mixed

Parameters

$name

string

Returns

mixed

Retrieve action controller instantiation parameters

getParams() : array

Returns

array

Retrieve a plugin or plugins by class

getPlugin(string $class) : false | \Zend_Controller_Plugin_Abstract | array

Parameters

$class

string

Returns

false\Zend_Controller_Plugin_Abstractarray

Retrieve all plugins

getPlugins() : array

Returns

array

Return the request object.

getRequest() : null | \Zend_Controller_Request_Abstract

Returns

null\Zend_Controller_Request_Abstract

Return the response object.

getResponse() : null | \Zend_Controller_Response_Abstract

Returns

null\Zend_Controller_Response_Abstract

Return the router object.

getRouter() : \Zend_Controller_Router_Interface

Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.

Returns

\Zend_Controller_Router_Interface

Is a particular plugin registered?

hasPlugin(string $class) : boolean

Parameters

$class

string

Returns

boolean

Register a plugin.

registerPlugin(\Zend_Controller_Plugin_Abstract $plugin, integer $stackIndex = null) : \Zend_Controller_Front

Parameters

$plugin

\Zend_Controller_Plugin_Abstract

$stackIndex

integer

Optional; stack index for plugin

Returns

\Zend_Controller_Front

Remove a controller directory by module name

removeControllerDirectory(string $module) : boolean

Parameters

$module

string

Returns

boolean

Resets all object properties of the singleton instance

resetInstance() : void

Primarily used for testing; could be used to chain front controllers.

Also resets action helper broker, clearing all registered helpers.

Set whether {@link dispatch()} should return the response without first rendering output. By default, output is rendered and dispatch() returns nothing.

returnResponse(boolean $flag = null) : boolean | \Zend_Controller_Front

Parameters

$flag

boolean

Returns

boolean\Zend_Controller_FrontUsed as a setter, returns object; as a getter, returns boolean

Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()

run(string|array $controllerDirectory) : void
Static

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.

Parameters

$controllerDirectory

stringarray

Path to Zend_Controller_Action controller classes or array of such paths

Exceptions

\Zend_Controller_Exception if called from an object instance

Set the base URL used for requests

setBaseUrl(string $base = null) : \Zend_Controller_Front

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:

If a null value is passed, this can be used as well for autodiscovery (default).

Parameters

$base

string

Exceptions

\Zend_Controller_Exception for non-string $base

Returns

\Zend_Controller_Front

Set controller directory

setControllerDirectory(string|array $directory, string $module = null) : \Zend_Controller_Front

Stores controller directory(ies) in dispatcher. May be an array of directories or a string containing a single directory.

Parameters

$directory

stringarray

Path to Zend_Controller_Action controller classes or array of such paths

$module

string

Optional module name to use with string $directory

Returns

\Zend_Controller_Front

Set the default action (unformatted string)

setDefaultAction(string $action) : \Zend_Controller_Front

Parameters

$action

string

Returns

\Zend_Controller_Front

Set the default controller (unformatted string)

setDefaultControllerName(string $controller) : \Zend_Controller_Front

Parameters

$controller

string

Returns

\Zend_Controller_Front

Set the default module name

setDefaultModule(string $module) : \Zend_Controller_Front

Parameters

$module

string

Returns

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

setDispatcher(\Zend_Controller_Dispatcher_Interface $dispatcher) : \Zend_Controller_Front

Parameters

$dispatcher

\Zend_Controller_Dispatcher_Interface

Returns

\Zend_Controller_Front

Set the directory name within a module containing controllers

setModuleControllerDirectoryName(string $name = 'controllers') : \Zend_Controller_Front

Parameters

$name

string

Returns

\Zend_Controller_Front

Add or modify a parameter to use when instantiating an action controller

setParam(string $name, mixed $value) : \Zend_Controller_Front

Parameters

$name

string

$value

mixed

Returns

\Zend_Controller_Front

Set parameters to pass to action controller constructors

setParams(array $params) : \Zend_Controller_Front

Parameters

$params

array

Returns

\Zend_Controller_Front

Set request class/object

setRequest(string|\Zend_Controller_Request_Abstract $request) : \Zend_Controller_Front

Set the request object. The request holds the request environment.

If a class name is provided, it will instantiate it

Parameters

$request

string\Zend_Controller_Request_Abstract

Exceptions

\Zend_Controller_Exception if invalid request class

Returns

\Zend_Controller_Front

Set response class/object

setResponse(string|\Zend_Controller_Response_Abstract $response) : \Zend_Controller_Front

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.

Parameters

$response

string\Zend_Controller_Response_Abstract

Exceptions

\Zend_Controller_Exception if invalid response class

Returns

\Zend_Controller_Front

Set router class/object

setRouter(string|\Zend_Controller_Router_Interface $router) : \Zend_Controller_Front

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

Parameters

$router

string\Zend_Controller_Router_Interface

Exceptions

\Zend_Controller_Exception if invalid router class

Returns

\Zend_Controller_Front

Set the throwExceptions flag and retrieve current status

throwExceptions(boolean $flag = null) : boolean | \Zend_Controller_Front

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.

Parameters

$flag

boolean

Defaults to null (return flag state)

Returns

boolean\Zend_Controller_FrontUsed as a setter, returns object; as a getter, returns boolean

Unregister a plugin.

unregisterPlugin(string|\Zend_Controller_Plugin_Abstract $plugin) : \Zend_Controller_Front

Parameters

$plugin

string\Zend_Controller_Plugin_Abstract

Plugin class or object to unregister

Returns

\Zend_Controller_Front

Constructor

__construct() : void

Instantiate using \getInstance(); front controller is a singleton object.

Instantiates the plugin broker.

Enforce singleton; disallow cloning

__clone() : void

 Properties

 

Base URL

$_baseUrl : string

Default

null
 

Directory|ies where controllers are stored

$_controllerDir : string | array

Default

null
 

Instance of Zend_Controller_Dispatcher_Interface

$_dispatcher : \Zend_Controller_Dispatcher_Interface

Default

null
 

Singleton instance

$_instance : \Zend_Controller_Front

Default

null
Static

Marked only as protected to allow extension of the class. To extend, simply override \getInstance().

 

Array of invocation parameters to use when instantiating action controllers

$_invokeParams : array

Default

array()
 

Subdirectory within a module containing controllers; defaults to 'controllers'

$_moduleControllerDirectoryName : string

Default

'controllers'
 

Instance of Zend_Controller_Plugin_Broker

$_plugins : \Zend_Controller_Plugin_Broker

Default

null
 

Instance of Zend_Controller_Request_Abstract

$_request : \Zend_Controller_Request_Abstract

Default

null
 

Instance of Zend_Controller_Response_Abstract

$_response : \Zend_Controller_Response_Abstract

Default

null
 

Whether or not to return the response prior to rendering output while in {@link dispatch()}; default is to send headers and render output.

$_returnResponse : boolean

Default

false
 

Instance of Zend_Controller_Router_Interface

$_router : \Zend_Controller_Router_Interface

Default

null
 

Whether or not exceptions encountered in {@link dispatch()} should be thrown or trapped in the response object

$_throwExceptions : boolean

Default

false