Jimit
Jimit

Reputation: 2259

Front controller object in zend framewok

What is diff. between below objects of front controller and how to use it?

$this->bootstrap('frontController');
    $frontController = $this->getResource('frontController');


    $front = Zend_Controller_Front::getInstance();

What is diff. between these two objects of front controller?

Upvotes: 1

Views: 943

Answers (1)

Fatmuemoo
Fatmuemoo

Reputation: 2217

Both

$frontController = $this->getResource('frontController');

and

$front = Zend_Controller_Front::getInstance();

will return the same instance of Zend_Controller_Front. Its a singleton, so by definition there can only be one instance of that object. The difference is when you execute

$this->bootstrap('frontController');

you are insuring that the bootstrap has executed the front controller resource, Zend_Application_Resource_Frontcontroller by default.

IMO, use the first example in your bootstraps and resources, use the latter everywhere else. They both get you the same instance of the front controller, the only benefit to the first example is that lets the bootstrap know that the front controller is a dependency.

Upvotes: 5

Related Questions