Zend Framework  1.12
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
Zend_Controller_Front Class Reference

Public Member Functions

 resetInstance ()
 Resets all object properties of the singleton instance.
 
 addControllerDirectory ($directory, $module=null)
 Add a controller directory to the controller directory stack.
 
 setControllerDirectory ($directory, $module=null)
 Set controller directory.
 
 getControllerDirectory ($name=null)
 Retrieve controller directory.
 
 removeControllerDirectory ($module)
 Remove a controller directory by module name.
 
 addModuleDirectory ($path)
 Specify a directory as containing modules.
 
 getModuleDirectory ($module=null)
 Return the path to a module directory (but not the controllers directory within)
 
 setModuleControllerDirectoryName ($name= 'controllers')
 Set the directory name within a module containing controllers.
 
 getModuleControllerDirectoryName ()
 Return the directory name within a module containing controllers.
 
 setDefaultControllerName ($controller)
 Set the default controller (unformatted string)
 
 getDefaultControllerName ()
 Retrieve the default controller (unformatted string)
 
 setDefaultAction ($action)
 Set the default action (unformatted string)
 
 getDefaultAction ()
 Retrieve the default action (unformatted string)
 
 setDefaultModule ($module)
 Set the default module name.
 
 getDefaultModule ()
 Retrieve the default module.
 
 setRequest ($request)
 Set request class/object.
 
 getRequest ()
 Return the request object.
 
 setRouter ($router)
 Set router class/object.
 
 getRouter ()
 Return the router object.
 
 setBaseUrl ($base=null)
 Set the base URL used for requests.
 
 getBaseUrl ()
 Retrieve the currently set base URL.
 
 setDispatcher (Zend_Controller_Dispatcher_Interface $dispatcher)
 Set the dispatcher object.
 
 getDispatcher ()
 Return the dispatcher object.
 
 setResponse ($response)
 Set response class/object.
 
 getResponse ()
 Return the response object.
 
 setParam ($name, $value)
 Add or modify a parameter to use when instantiating an action controller.
 
 setParams (array $params)
 Set parameters to pass to action controller constructors.
 
 getParam ($name)
 Retrieve a single parameter from the controller parameter stack.
 
 getParams ()
 Retrieve action controller instantiation parameters.
 
 clearParams ($name=null)
 Clear the controller parameter stack.
 
 registerPlugin (Zend_Controller_Plugin_Abstract $plugin, $stackIndex=null)
 Register a plugin.
 
 unregisterPlugin ($plugin)
 Unregister a plugin.
 
 hasPlugin ($class)
 Is a particular plugin registered?
 
 getPlugin ($class)
 Retrieve a plugin or plugins by class.
 
 getPlugins ()
 Retrieve all plugins.
 
 throwExceptions ($flag=null)
 Set the throwExceptions flag and retrieve current status.
 
 returnResponse ($flag=null)
 Set whether dispatch() should return the response without first rendering output.
 
 dispatch (Zend_Controller_Request_Abstract $request=null, Zend_Controller_Response_Abstract $response=null)
 Dispatch an HTTP request to a controller/action.
 

Static Public Member Functions

static getInstance ()
 Singleton instance.
 
static run ($controllerDirectory)
 Convenience feature, calls setControllerDirectory()->setRouter()->dispatch()
 

Protected Member Functions

 __construct ()
 Constructor.
 

Protected Attributes

 $_baseUrl = null
 
 $_controllerDir = null
 
 $_dispatcher = null
 
 $_invokeParams = array()
 
 $_moduleControllerDirectoryName = 'controllers'
 
 $_plugins = null
 
 $_request = null
 
 $_response = null
 
 $_returnResponse = false
 
 $_router = null
 
 $_throwExceptions = false
 

Static Protected Attributes

static $_instance = null
 

Constructor & Destructor Documentation

__construct ( )
protected

Constructor.

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

Instantiates the plugin broker.

Returns
void

Member Function Documentation

addControllerDirectory (   $directory,
  $module = null 
)

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.

Parameters
string$directory
string$moduleOptional argument; module with which to associate directory. If none provided, assumes 'default'
Returns
Zend_Controller_Front
Exceptions
Zend_Controller_Exceptionif directory not found or readable
addModuleDirectory (   $path)

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.

Parameters
string$path
Returns
Zend_Controller_Front
clearParams (   $name = null)

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.

Parameters
null|string|arraysingle key or array of keys for params to clear
Returns
Zend_Controller_Front
dispatch ( Zend_Controller_Request_Abstract  $request = null,
Zend_Controller_Response_Abstract  $response = null 
)

Dispatch an HTTP request to a controller/action.

Parameters
Zend_Controller_Request_Abstract | null$request
Zend_Controller_Response_Abstract | null$response
Returns
void|Zend_Controller_Response_Abstract Returns response object if returnResponse() is true

Instantiate default request object (HTTP version) if none provided

Set base URL of request object, if available

Instantiate default response object (HTTP version) if none provided

Register request and response objects with plugin broker

Initialize router

Initialize dispatcher

Route request to controller/action, if a router is provided

Notify plugins of router startup

Notify plugins of router completion

Notify plugins of dispatch loop startup

Attempt to dispatch the controller/action. If the $this->_request indicates that it needs to be dispatched, move to the next action in the request.

Notify plugins of dispatch startup

Skip requested action if preDispatch() has reset it

Dispatch request

Notify plugins of dispatch completion

Notify plugins of dispatch loop completion

getBaseUrl ( )

Retrieve the currently set base URL.

Returns
string
getControllerDirectory (   $name = 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
Parameters
string$nameDefault null
Returns
array|string|null
getDefaultAction ( )

Retrieve the default action (unformatted string)

Returns
string
getDefaultControllerName ( )

Retrieve the default controller (unformatted string)

Returns
string
getDefaultModule ( )

Retrieve the default module.

Returns
string
getDispatcher ( )

Return the dispatcher object.

Returns
Zend_Controller_Dispatcher_Interface

Instantiate the default dispatcher if one was not set.

static getInstance ( )
static

Singleton instance.

Returns
Zend_Controller_Front
getModuleControllerDirectoryName ( )

Return the directory name within a module containing controllers.

Returns
string
getModuleDirectory (   $module = null)

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

Parameters
string$module
Returns
string|null
getParam (   $name)

Retrieve a single parameter from the controller parameter stack.

Parameters
string$name
Returns
mixed
getParams ( )

Retrieve action controller instantiation parameters.

Returns
array
getPlugin (   $class)

Retrieve a plugin or plugins by class.

Parameters
string$class
Returns
false|Zend_Controller_Plugin_Abstract|array
getPlugins ( )

Retrieve all plugins.

Returns
array
getRequest ( )

Return the request object.

Returns
null|Zend_Controller_Request_Abstract
getResponse ( )

Return the response object.

Returns
null|Zend_Controller_Response_Abstract
getRouter ( )

Return the router object.

Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.

Returns
Zend_Controller_Router_Interface
hasPlugin (   $class)

Is a particular plugin registered?

Parameters
string$class
Returns
bool
registerPlugin ( Zend_Controller_Plugin_Abstract  $plugin,
  $stackIndex = null 
)

Register a plugin.

Parameters
Zend_Controller_Plugin_Abstract$plugin
int$stackIndexOptional; stack index for plugin
Returns
Zend_Controller_Front
removeControllerDirectory (   $module)

Remove a controller directory by module name.

Parameters
string$module
Returns
bool
resetInstance ( )

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.

Returns
void
returnResponse (   $flag = null)

Set whether dispatch() should return the response without first rendering output.

By default, output is rendered and dispatch() returns nothing.

Parameters
boolean$flag
Returns
boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
static run (   $controllerDirectory)
static

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.

Parameters
string | array$controllerDirectoryPath to Zend_Controller_Action controller classes or array of such paths
Returns
void
Exceptions
Zend_Controller_Exceptionif called from an object instance
setBaseUrl (   $base = null)

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:

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

Parameters
string$base
Returns
Zend_Controller_Front
Exceptions
Zend_Controller_Exceptionfor non-string $base
setControllerDirectory (   $directory,
  $module = null 
)

Set controller directory.

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

Parameters
string | array$directoryPath to Zend_Controller_Action controller classes or array of such paths
string$moduleOptional module name to use with string $directory
Returns
Zend_Controller_Front
setDefaultAction (   $action)

Set the default action (unformatted string)

Parameters
string$action
Returns
Zend_Controller_Front
setDefaultControllerName (   $controller)

Set the default controller (unformatted string)

Parameters
string$controller
Returns
Zend_Controller_Front
setDefaultModule (   $module)

Set the default module name.

Parameters
string$module
Returns
Zend_Controller_Front
setDispatcher ( Zend_Controller_Dispatcher_Interface  $dispatcher)

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.

Parameters
Zend_Controller_Dispatcher_Interface$dispatcher
Returns
Zend_Controller_Front
setModuleControllerDirectoryName (   $name = 'controllers')

Set the directory name within a module containing controllers.

Parameters
string$name
Returns
Zend_Controller_Front
setParam (   $name,
  $value 
)

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

Parameters
string$name
mixed$value
Returns
Zend_Controller_Front
setParams ( array  $params)

Set parameters to pass to action controller constructors.

Parameters
array$params
Returns
Zend_Controller_Front
setRequest (   $request)

Set request class/object.

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

If a class name is provided, it will instantiate it

Parameters
string | Zend_Controller_Request_Abstract$request
Exceptions
Zend_Controller_Exceptionif invalid request class
Returns
Zend_Controller_Front
setResponse (   $response)

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.

Parameters
string | Zend_Controller_Response_Abstract$response
Exceptions
Zend_Controller_Exceptionif invalid response class
Returns
Zend_Controller_Front
setRouter (   $router)

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

Parameters
string | Zend_Controller_Router_Interface$router
Exceptions
Zend_Controller_Exceptionif invalid router class
Returns
Zend_Controller_Front
throwExceptions (   $flag = null)

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.

Parameters
boolean$flagDefaults to null (return flag state)
Returns
boolean|Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
unregisterPlugin (   $plugin)

Unregister a plugin.

Parameters
string | Zend_Controller_Plugin_Abstract$pluginPlugin class or object to unregister
Returns
Zend_Controller_Front

Member Data Documentation

$_baseUrl = null
protected
$_controllerDir = null
protected
$_dispatcher = null
protected
$_instance = null
staticprotected
$_invokeParams = array()
protected
$_moduleControllerDirectoryName = 'controllers'
protected
$_plugins = null
protected
$_request = null
protected
$_response = null
protected
$_returnResponse = false
protected
$_router = null
protected
$_throwExceptions = false
protected