View Single Post
  #1 (permalink)  
Old 04-18-2008, 07:36 AM
snairl snairl is offline
Junior Member
 
Join Date: Apr 2008
Posts: 7
Default Zend_Controller Initialization

Hi guys,

I have the following controller

PHP Code:
<?php

class IndexController extends Zend_Controller_Action
{
    
    function 
init()
    {
        echo 
'INDEX CONTROLLER';
    }    

    function 
indexAction()
    {
        
$this->_forward('test');
    }

    function 
testAction()
    {
    }
    
}
The strange result I get is that "init()" method is called twice when I access my index action. Is that correct behavior?
Also I notice the following if I use the action stack like this:
PHP Code:
$this->_helper->actionStack('testa''test');
        
$this->_helper->actionStack('testb''test');
        
$this->_helper->actionStack('testaa''test'); 
Which simply calls the "test" controller actions "testaa", "testb" and "testc".
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:
<?php

class IndexController extends Zend_Controller_Action
{
    
    function 
init()
    {
        
$this->_helper->actionStack('test''index');
    }    

    function 
indexAction()
    {
    }

    function 
testAction()
    {
    }
    
}
when you invoke indexAction() the page will just hang on because when in init method invoking testAction via the action stack helper, it invokes init() for testAction(), then in init() action stack helper again invoke testAction() and so on in one endless loop.

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
Reply With Quote