PhpRiot
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

Environmental Accessor Methods

In addition to the methods listed above, there are a number of accessor methods that can be used to affect the front controller environment -- and thus the environment of the classes to which the front controller delegates.

  • resetInstance() can be used to clear all current settings. Its primary purpose is for testing, but it can also be used for instances where you wish to chain together multiple front controllers.

  • setDefaultControllerName() and getDefaultControllerName() let you specify a different name to use for the default controller ('index' is used otherwise) and retrieve the current value. They proxy to the dispatcher.

  • setDefaultAction() and getDefaultAction() let you specify a different name to use for the default action ('index' is used otherwise) and retrieve the current value. They proxy to the dispatcher.

  • setRequest() and getRequest() let you specify the request class or object to use during the dispatch process and to retrieve the current object. When setting the request object, you may pass in a request class name, in which case the method will load the class file and instantiate it.

  • setRouter() getRouter() let you specify the router class or object to use during the dispatch process and to retrieve the current object. When setting the router object, you may pass in a router class name, in which case the method will load the class file and instantiate it.

    When retrieving the router object, it first checks to see if one is present, and if not, instantiates the default router (rewrite router).

  • setBaseUrl() and getBaseUrl() let you specify the base URL to strip when routing requests and to retrieve the current value. The value is provided to the request object just prior to routing.

    Fully-Qualified URL is not supported

    Passing a fully-qualified URL (ie: http://example.com/) to the setBaseUrl method is not supported, and will cause issues when using the URL view helper. See ticket ZF-10923 for more details.

  • setDispatcher() and getDispatcher() let you specify the dispatcher class or object to use during the dispatch process and retrieve the current object. When setting the dispatcher object, you may pass in a dispatcher class name, in which case the method will load the class file and instantiate it.

    When retrieving the dispatcher object, it first checks to see if one is present, and if not, instantiates the default dispatcher.

  • setResponse() and getResponse() let you specify the response class or object to use during the dispatch process and to retrieve the current object. When setting the response object, you may pass in a response class name, in which case the method will load the class file and instantiate it.

  • registerPlugin(Zend_Controller_Plugin_Abstract $plugin, $stackIndex = null) allows you to register plugin objects. By setting the optional $stackIndex, you can control the order in which plugins will execute.

  • unregisterPlugin($plugin) let you unregister plugin objects. $plugin may be either a plugin object or a string denoting the class of plugin to unregister.

  • throwExceptions($flag) is used to turn on/off the ability to throw exceptions during the dispatch process. By default, exceptions are caught and placed in the response object; turning on throwExceptions() will override this behaviour.

    For more information, read MVC Exceptions.

  • returnResponse($flag) is used to tell the front controller whether to return the response (TRUE) from dispatch(), or if the response should be automatically emitted (FALSE). By default, the response is automatically emitted (by calling Zend_Controller_Response_Abstract::sendResponse()); turning on returnResponse() will override this behaviour.

    Reasons to return the response include a desire to check for exceptions prior to emitting the response, needing to log various aspects of the response (such as headers), etc.

Zend Framework