Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


Probably the most common resource you will load with Zend_Application will be the Front Controller resource, which provides the ability to configure Zend_Controller_Front. This resource provides the ability to set arbitrary front controller parameters, specify plugins to initialize, and much more.

Once initialized, the resource assigns the $frontController property of the bootstrap to the Zend_Controller_Front instance.

Available configuration keys include the following, and are case insensitive:

  • controllerDirectory: either a string value specifying a single controller directory, or an array of module to controller directory pairs.

  • moduleControllerDirectoryName: a string value indicating the subdirectory under a module that contains controllers.

  • moduleDirectory: directory under which modules may be found.

  • defaultControllerName: base name of the default controller (normally "index").

  • defaultAction: base name of the default action (normally "index").

  • defaultModule: base name of the default module (normally "default").

  • baseUrl: explicit base URL to the application (normally auto-detected).

  • plugins: array of front controller plugin class names. The resource will instantiate each class (with no constructor arguments) and then register the instance with the front controller. If you want to register a plugin with a particular stack index, you need to provide an array with two keys class and stackIndex.

  • params: array of key to value pairs to register with the front controller.

  • returnresponse: whether or not to return the response object after dispatching the front controller. Value should be a boolean; by default, this is disabled.

  • dispatcher: allows overriding the default dispatcher. Has two subkeys, class (the classname of new dispatcher) and params, an array of parameters to pass to the dispatcher constructor.

    Example 34. Overriding the dispatcher

    resources.frontController.dispatcher.class = "My_Custom_Dispatcher" = "bar"
    resources.frontController.dispatcher.params.baz = "grok"

If an unrecognized key is provided, it is registered as a front controller parameter by passing it to setParam().

Example 35. Sample Front Controller resource configuration

Below is a sample INI snippet showing how to configure the front controller resource.

resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.moduleControllerDirectoryName = "actions"
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.defaultControllerName = "site"
resources.frontController.defaultAction = "home"
resources.frontController.defaultModule = "static"
resources.frontController.baseUrl = "/subdir" = "My_Plugin_Foo" = "My_Plugin_Bar"
resources.frontController.plugins.baz.class = "My_Plugin_Baz"
resources.frontController.plugins.baz.stackIndex = 123
resources.frontController.returnresponse = 1
resources.frontController.env = APPLICATION_ENV

; The following proxies to:
; Zend_Controller_Action_HelperBroker::addPath('Helper_Path', $helperPrefix);
resources.frontController.actionHelperPaths.HELPER_Prefix = "My/Helper/Path"

Example 36. Retrieving the Front Controller in your bootstrap

Once your Front Controller resource has been initialized, you can fetch the Front Controller instance via the $frontController property of your bootstrap.

$front $bootstrap->frontController;

Zend Framework