|
|||
|
Hi guys,
I have the following controller PHP Code:
Also I notice the following if I use the action stack like this: PHP Code:
However the Test::init() method is called each time regarding the class was already instantiate with the first method. Is that correct that "init()" is called each time the action is invoked from this controller? I think this is a bug anyway. The problem is that if you have controller like this: PHP Code:
Also I would ask for some advise how to invoke other actions parallel to requested one in the init() method. Of course I can put the action stack helper calls in each actions I would like to but duplication is not what I think DRY means ![]() Regards Boris |
|
||||
|
Yes the init() funciton is run for every request against the controller, so you run three actions from that controller during the request init() will run three times. __construct() runs only once and preDispatch() plugins will only run once as well I believe. init() is run per action call to facilitate tailoring the controller initialization for the action being requested. Its not a bug. If you create a endless loop with forward calls then YOU have created the logical error condition. To call an action without running init() you do $this->testAction(); A controller is still an object and can be used as one as long as your action definitions don't muck it up.
I don't think you can really get parallel execution out of Apache on *nix or *dows but I'm not sure about that.
__________________
Zend Framework Resources: Zend Webinars | Reference Manual | API Docs | Books | FreeNode: #zftalk Getting Started Tutorials: Getting started with ZF | Getting started with Zend Auth |
|
|||
|
I think you're almost there. However based on manual the init() is called only once from the constructor. I also checked the code and it's correct the init() is called once in the constructor for ZF 1.5 Action.php@line:129
However the phenomenon is still exist. Try out this code PHP Code:
Logically this means that the dispatcher create two instances of this controller and run them one after another. For me this is not correct as the both action shared one class and I expect they to share the same class so I will preserve context and re-init() will be not needed. To proof my words try this code: PHP Code:
Why it's needed to initialize same things twice I can't understand. What to say more! |
|
||||
|
it's because $this->_forward starts the dispatch process all over vs. $this->testAction() referencing the current object. _forward creates another request on the dispatch stack.
__________________
Zend Framework Resources: Zend Webinars | Reference Manual | API Docs | Books | FreeNode: #zftalk Getting Started Tutorials: Getting started with ZF | Getting started with Zend Auth |
|
|||
|
The simple answer is that forward is not meant to be used to forward between actions in the same controller. Do what Elemental says and call the method directly.
Last edited by Leif.Högberg : 04-24-2008 at 10:09 AM. Reason: Typo |
![]() |
| Thread Tools | |
| Display Modes | |
|
|