开发者

Initializing the Front Controller, what's the difference between these two

I'm looking at some of the code I've written for Zend over the past 2 months and I see some inconsistency (because I'm a beginner) in initializing the front controller.

I see that sometimes I've done this

$frontController = Zend_Controller_F开发者_高级运维ront::getInstance();

and other times I've done this

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

Not sure what I was thinking. I guess I was probably following examples. Anyone knows if there's any real difference between these two?


One is a call to a Singleton object, which can be fetched from anywhere. The other is a call to the application bootstrapper, to retrieve a resource called 'FrontController'.

In theory, the resource called 'FrontController' could be anything that was assigned to the bootstrap with that name, such as a custom front controller implementation, if you didn't care to use Zend's.

In practice, they both retrieve the Zend_Controller_Front instance.


Zend_Controller_Front::getInstance()

The first method is a direct call to Zend_Controller_Front.

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

The second method uses Zend_Application with Zend_Application_Bootstrap_ResourceBootstrapper. When initializing Zend_Application, it registers FrontController resource, which is then initialized with the $this->bootstrap call in your bootstrap file.

While the latter method will require both Zend_Application and Zend_Controller, the first method only depends on Zend_Controller.


I think it is two of the same kind ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜