thanks for the reply Matthew

Can I ask why _forward() stacks and only forwards at the end of the current controller method? I couldn't find any reference to why it works this way in the docs so when some of the guys in the office had used multiple forwards (without returns) the default behaviour was confusing.

best wishes,
Si


On 13 Feb 2008, at 19:36, Matthew Weier O'Phinney wrote:

Correct -- you need to return. I actually usually write it as:

   return $this->_forward('index', 'login');

as the return value of an action is ignored anyways.

The reason it works this way (i.e., you need to return when forwarding)
is because you can't have a called function force the calling function
to return -- it's a language limitation.

Further to this, if the above is the recommended way to forward and quit the current method then this of course becomes problematic if I abstracted
the login check. I.e. if I called a function to do something like:

 $this->checkLogin();

And the function checkLogin() did the necessary ACL check and also included
the forward() - to avoid DRY.

Unfortunate, but necessary. I typically have methods like this return a
boolean, so I can then do something like this:

   if (!$this->checkLogin() {
       return $this->_forward('index', 'login');
   }



Reply via email to