Wednesday, November 3, 2010

Component-based Re-directs in CakePHP

On any given day you might want to write a CakePHP component that say does some simplified user authentication. If improper credentials are received you'd probably want to re-direct to some sort of error page. It makes sense. Seems like a common thing. Guess what? This is tricky.

See: http://www.dom111.co.uk/blog/coding/cakephp-components-redirect-fail-on-my-part/171

Then see: http://book.cakephp.org/view/65/MVC-Class-Access-Within-Components

The answer:

For reasons which are explained in the above two articles, components that wish to use redirect need to include the following callback function in their component:

function beforeRedirect(&$controller, $url, $status=null, $exit=true) {
 }


Kinda weird, huh?

Yeah, I knew you'd agree.

No comments:

Post a Comment