Search code examples
phpzend-frameworkzend-controller

Zend_Controller Following PEAR Naming Convention


I am developing a web-app using zend framework. I like how all the autoloading works however I don't really like the way Zend_Controller names the controllers by default. I am looking for a way to enable zend_controller to understand my controller class named Controller_User stored in {$app}/Controller/User.php . Is there anyway I can do this with least amount of extra code?


Solution

  • a subclassed dispatcher ( quoted from http://cslai.coolsilon.com/2009/03/28/extending-zend-framework/ )

    class Coolsilon_Controller_Dispatcher 
        extends Zend_Controller_Dispatcher_Standard { 
        public function __construct() { 
            parent::__construct(); 
        } 
    
        public function formatControllerName($unformatted) { 
            return sprintf( 
                'Controller_%s', ucfirst($this->_formatName($unformatted)) 
            ); 
        } 
    
        public function formatActionName($unformatted) { 
            $formatted = $this->_formatName($unformatted, true); 
            return strtolower(substr($formatted, 0, 1)) . substr($formatted, 1); 
        } 
    }