Chicobanbe
Chicobanbe

Reputation: 11

run function in bootstrap file

I use custom library in Zend Framework with namespace MY, I register it in Bootstrap.php file (Application/Bootstrap.php)

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    public function run()
    {
        $frontController = Zend_Controller_Front::getInstance();
        Zend_Loader_Autoloader::getInstance()->registerNamespace('My');
        $frontController->dispatch();
    }
}

It is OK, but when I change the name run() to _initRegisterNamespace()

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
        public function _initRegisterNamespace()
        {
            $frontController = Zend_Controller_Front::getInstance();
            Zend_Loader_Autoloader::getInstance()->registerNamespace('My');
            $frontController->dispatch();
        }
    }

It is not OK, there are many error. Because Bootstrap will run every function with start "_init". Why don't I use _init function to register namespace. Thank for answering!

Upvotes: 1

Views: 73

Answers (2)

Tim Fountain
Tim Fountain

Reputation: 33148

This is all that you need:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    public function _initRegisterNamespace()
    {
        Zend_Loader_Autoloader::getInstance()->registerNamespace('My');
    }
}

if that doesn't work please provide some info about the errors you're getting.

Upvotes: 0

homelessDevOps
homelessDevOps

Reputation: 20726

If you want to Register your "My" Namespace try this:

protected function _initNamespace()
{

    $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'My',
            'basePath'  => dirname(__FILE__),
    ));

    return $autoloader;
}

Dispatch is not necessary.

Upvotes: 1

Related Questions