The problem is that Zend_Controller_Front is a singleton - once you call getInstance() using Zend_Controller_Front::getInstance() it statically stores a Zend_Controller_Front object for future calls. When you subclass the front controller, e.g. My_Controller_Front, it has no impact on any static stores so calling My_Controller_Front::getInstance() simply returns the very first Front Controller object called. This is fine, if you call your subclass first - but it's not if you used the original Zend_Controller_Front. To get around this, you can overload getInstance in your subclass to use a static $_instance var from your subclass - this will ensure My_Controller_Front always returns a My_Controller_Front object without fail.
Paddy
Pádraic Brady
http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative
From: Yunfeng Xu <hywl51@gmail.com>
To: fw-mvc@lists.zend.com
Sent: Thursday, July 23, 2009 5:22:44 AM
Subject: [fw-mvc] Overriding the Zend_Controller_Front::getInstance()?
Hi,
When I read the official zend framework programmer's reference guide - 12.3.5. Extending the Front Controller, I got the following text at the bottom of the page:
Overriding the
I don't understand why
Please can someone give me some advise?
Thanks
Yunfeng
Paddy
http://blog.astrumfutura.com
http://www.survivethedeepend.com
OpenID Europe Foundation Irish Representative
From: Yunfeng Xu <hywl51@gmail.com>
To: fw-mvc@lists.zend.com
Sent: Thursday, July 23, 2009 5:22:44 AM
Subject: [fw-mvc] Overriding the Zend_Controller_Front::getInstance()?
Hi,
When I read the official zend framework programmer's reference guide - 12.3.5. Extending the Front Controller, I got the following text at the bottom of the page:
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. I don't understand why
Zend_Controller_Front::getInstance()
will return an instance of my new subclass only if I overriding the getInstance()method, and where I should put the overriding code.Please can someone give me some advise?
Thanks
Yunfeng
没有评论:
发表评论