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:
class IndexController extends Zend_Controller_Action
{
function init()
{
echo 'INDEX CONTROLLER';
}
function indexAction()
{
$this->_forward('test');
}
function testAction()
{
}
}
You should see text "INDEX CONTROLLER" twice. I can explain this only with that not only init() is run twice but and the _construct() itself.
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:
class IndexController extends Zend_Controller_Action
{
public function __construct(Zend_Controller_Request_Abstract $request, Zend_Controller_Response_Abstract $response, array $invokeArgs = array())
{
parent::__construct($request, $response, $invokeArgs);
echo 'CONSTRUCTOR<br>';
}
function init()
{
echo 'INDEX CONTROLLER';
}
function indexAction()
{
$this->_forward('test');
}
function testAction()
{
}
}
If you start it with ZF 1.5 you'll see "CONSTRUCTOR" twice.
Why it's needed to initialize same things twice I can't understand.
What to say more!