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

Extending the Front Controller

To extend the Front Controller, at the very minimum you will need to override the getInstance() method:

<?php
class My_Controller_Front extends Zend_Controller_Front
{
    public static function 
getInstance()
    {
        if (
null === self::$_instance) {
            
self::$_instance = new self();
        }

        return 
self::$_instance;
    }
}

Overriding the getInstance() method ensures that subsequent calls to Zend_Controller_Front::getInstance() will return an instance of your new subclass instead of a Zend_Controller_Front instance -- this is particularly useful for some of the alternate routers and view helpers.

Typically, you will not need to subclass the front controller unless you need to add new functionality (for instance, a plugin autoloader, or a way to specify action helper paths). Some points where you may want to alter behaviour may include modifying how controller directories are stored, or what default router or dispatcher are used.

Zend Framework