API Documentation

Zend/Controller/Front.php

Show: inherited
Table of Contents

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-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  
Package
Zend_Controller  
Version
$Id: Front.php 24594 2012-01-05 21:27:01Z matthew $  

\Zend_Controller_Front

Package: Zend\Controller

Category
Zend  
Copyright
Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)  
License
New BSD License  

Properties

Propertyprotectedstring  $_baseUrl= 'null'

Base URL

Default valuenullDetails
Type
string
Propertyprotectedstring|array  $_controllerDir= 'null'

Directory|ies where controllers are stored

Default valuenullDetails
Type
stringarray
Propertyprotected\Zend_Controller_Dispatcher_Interface  $_dispatcher= 'null'

Instance of Zend_Controller_Dispatcher_Interface

Default valuenullDetails
Type
\Zend_Controller_Dispatcher_Interface
Propertyprotected\Zend_Controller_Front  $_instance= 'null'
static

Singleton instance

Marked only as protected to allow extension of the class. To extend, simply override {@link getInstance()}.

Default valuenullDetails
Type
\Zend_Controller_Front
Propertyprotectedarray  $_invokeParams= 'array()'

Array of invocation parameters to use when instantiating action controllers

Default valuearray()Details
Type
array
Propertyprotectedstring  $_moduleControllerDirectoryName= ''controllers''

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

Default value'controllers'Details
Type
string
Propertyprotected\Zend_Controller_Plugin_Broker  $_plugins= 'null'

Instance of Zend_Controller_Plugin_Broker

Default valuenullDetails
Type
\Zend_Controller_Plugin_Broker
Propertyprotected\Zend_Controller_Request_Abstract  $_request= 'null'

Instance of Zend_Controller_Request_Abstract

Default valuenullDetails
Type
\Zend_Controller_Request_Abstract
Propertyprotected\Zend_Controller_Response_Abstract  $_response= 'null'

Instance of Zend_Controller_Response_Abstract

Default valuenullDetails
Type
\Zend_Controller_Response_Abstract
Propertyprotectedboolean  $_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.

Default valuefalseDetails
Type
boolean
Propertyprotected\Zend_Controller_Router_Interface  $_router= 'null'

Instance of Zend_Controller_Router_Interface

Default valuenullDetails
Type
\Zend_Controller_Router_Interface
Propertyprotectedboolean  $_throwExceptions= 'false'

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

Default valuefalseDetails
Type
boolean

Methods

methodprivate__clone( ) : void

Enforce singleton; disallow cloning

methodprotected__construct( ) : void

Constructor

Instantiate using {@link getInstance()}; front controller is a singleton object.

Instantiates the plugin broker.

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

Parameters
Name Type Description
$directory string
$module string

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

Returns
Type Description
\Zend_Controller_Front
Throws
Exception Description
\Zend_Controller_Exception if directory not found or readable
methodpublicaddModuleDirectory( 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 {@link $_moduleControllerDirectoryName} will be used as the controller directory path.

Parameters
Name Type Description
$path string
Returns
Type Description
\Zend_Controller_Front
methodpublicclearParams( 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.

Parameters
Name Type Description
$name null|string|array

single key or array of keys for params to clear

Returns
Type Description
\Zend_Controller_Front
methodpublicdispatch( \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.

Parameters
Name Type Description
$request \Zend_Controller_Request_Abstract|null
$response \Zend_Controller_Response_Abstract|null
Returns
Type Description
void|\Zend_Controller_Response_Abstract Returns response object if returnResponse() is true
methodpublicgetBaseUrl( ) : string

Retrieve the currently set base URL

Returns
Type Description
string
methodpublicgetControllerDirectory( 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

Parameters
Name Type Description
$name string

Default null

Returns
Type Description
array|string|null
methodpublicgetDefaultAction( ) : string

Retrieve the default action (unformatted string)

Returns
Type Description
string
methodpublicgetDefaultControllerName( ) : string

Retrieve the default controller (unformatted string)

Returns
Type Description
string
methodpublicgetDefaultModule( ) : string

Retrieve the default module

Returns
Type Description
string
methodpublicgetDispatcher( ) : \Zend_Controller_Dispatcher_Interface

Return the dispatcher object.

Returns
Type Description
\Zend_Controller_Dispatcher_Interface
methodpublicgetInstance( ) : \Zend_Controller_Front
static

Singleton instance

Returns
Type Description
\Zend_Controller_Front
methodpublicgetModuleControllerDirectoryName( ) : string

Return the directory name within a module containing controllers

Returns
Type Description
string
methodpublicgetModuleDirectory( string $module = null ) : string|null

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

Parameters
Name Type Description
$module string
Returns
Type Description
string|null
methodpublicgetParam( string $name ) : mixed

Retrieve a single parameter from the controller parameter stack

Parameters
Name Type Description
$name string
Returns
Type Description
mixed
methodpublicgetParams( ) : array

Retrieve action controller instantiation parameters

Returns
Type Description
array
methodpublicgetPlugin( string $class ) : false|\Zend_Controller_Plugin_Abstract|array

Retrieve a plugin or plugins by class

Parameters
Name Type Description
$class string
Returns
Type Description
false|\Zend_Controller_Plugin_Abstract|array
methodpublicgetPlugins( ) : array

Retrieve all plugins

Returns
Type Description
array
methodpublicgetRequest( ) : null|\Zend_Controller_Request_Abstract

Return the request object.

Returns
Type Description
null|\Zend_Controller_Request_Abstract
methodpublicgetResponse( ) : null|\Zend_Controller_Response_Abstract

Return the response object.

Returns
Type Description
null|\Zend_Controller_Response_Abstract
methodpublicgetRouter( ) : \Zend_Controller_Router_Interface

Return the router object.

Instantiates a Zend_Controller_Router_Rewrite object if no router currently set.

Returns
Type Description
\Zend_Controller_Router_Interface
methodpublichasPlugin( string $class ) : bool

Is a particular plugin registered?

Parameters
Name Type Description
$class string
Returns
Type Description
bool
methodpublicregisterPlugin( \Zend_Controller_Plugin_Abstract $plugin, int $stackIndex = null ) : \Zend_Controller_Front

Register a plugin.

Parameters
Name Type Description
$plugin \Zend_Controller_Plugin_Abstract
$stackIndex int

Optional; stack index for plugin

Returns
Type Description
\Zend_Controller_Front
methodpublicremoveControllerDirectory( string $module ) : bool

Remove a controller directory by module name

Parameters
Name Type Description
$module string
Returns
Type Description
bool
methodpublicresetInstance( ) : 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.

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

Parameters
Name Type Description
$flag boolean
Returns
Type Description
boolean|\Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
methodpublicrun( string|array $controllerDirectory ) : void
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
Name Type Description
$controllerDirectory string|array

Path to Zend_Controller_Action controller classes or array of such paths

Throws
Exception Description
\Zend_Controller_Exception if called from an object instance
methodpublicsetBaseUrl( 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).

Parameters
Name Type Description
$base string
Returns
Type Description
\Zend_Controller_Front
Throws
Exception Description
\Zend_Controller_Exception for non-string $base
methodpublicsetControllerDirectory( 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.

Parameters
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

Returns
Type Description
\Zend_Controller_Front
methodpublicsetDefaultAction( string $action ) : \Zend_Controller_Front

Set the default action (unformatted string)

Parameters
Name Type Description
$action string
Returns
Type Description
\Zend_Controller_Front
methodpublicsetDefaultControllerName( string $controller ) : \Zend_Controller_Front

Set the default controller (unformatted string)

Parameters
Name Type Description
$controller string
Returns
Type Description
\Zend_Controller_Front
methodpublicsetDefaultModule( string $module ) : \Zend_Controller_Front

Set the default module name

Parameters
Name Type Description
$module string
Returns
Type Description
\Zend_Controller_Front
methodpublicsetDispatcher( \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.

Parameters
Name Type Description
$dispatcher \Zend_Controller_Dispatcher_Interface
Returns
Type Description
\Zend_Controller_Front
methodpublicsetModuleControllerDirectoryName( string $name = 'controllers' ) : \Zend_Controller_Front

Set the directory name within a module containing controllers

Parameters
Name Type Description
$name string
Returns
Type Description
\Zend_Controller_Front
methodpublicsetParam( string $name, mixed $value ) : \Zend_Controller_Front

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

Parameters
Name Type Description
$name string
$value mixed
Returns
Type Description
\Zend_Controller_Front
methodpublicsetParams( array $params ) : \Zend_Controller_Front

Set parameters to pass to action controller constructors

Parameters
Name Type Description
$params array
Returns
Type Description
\Zend_Controller_Front
methodpublicsetRequest( 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

Parameters
Name Type Description
$request string|\Zend_Controller_Request_Abstract
Returns
Type Description
\Zend_Controller_Front
Throws
Exception Description
\Zend_Controller_Exception if invalid request class
methodpublicsetResponse( 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.

Parameters
Name Type Description
$response string|\Zend_Controller_Response_Abstract
Returns
Type Description
\Zend_Controller_Front
Throws
Exception Description
\Zend_Controller_Exception if invalid response class
methodpublicsetRouter( 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 {@link setParam()} or {@link setParams()}.

Parameters
Name Type Description
$router string|\Zend_Controller_Router_Interface
Returns
Type Description
\Zend_Controller_Front
Throws
Exception Description
\Zend_Controller_Exception if invalid router class
methodpublicthrowExceptions( 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.

Parameters
Name Type Description
$flag boolean

Defaults to null (return flag state)

Returns
Type Description
boolean|\Zend_Controller_Front Used as a setter, returns object; as a getter, returns boolean
methodpublicunregisterPlugin( string|\Zend_Controller_Plugin_Abstract $plugin ) : \Zend_Controller_Front

Unregister a plugin.

Parameters
Name Type Description
$plugin string|\Zend_Controller_Plugin_Abstract

Plugin class or object to unregister

Returns
Type Description
\Zend_Controller_Front
Documentation was generated by DocBlox 0.15.1.