Thursday, April 28, 2011

ZF: performing redirect inside model

I've chosen to move Form processing from Controller to MyForm class, in order to follow ThinController/FatModel rule. But some of my code in Zend_Form class needs to perform a redirect.

In Zend_Controller_Action my redirect was:

$this->_redirect('/');

What would it become in Zend_Form?

From stackoverflow
  • $redirector =
        Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
    $redirector->gotoSimple('index','index');
    
  • It's not a model component, if you redirect from within it. You should only do redirects from the presentation layer.


    What would be an example of this? Lets suppose that currently I have a simple RecordForm class, and in its init() I am doing redirect after lines where I check record update was successfull.

    You could let the function return a value indicating success/failure, and let the caller (the controller) perform a redirect based on the result.

    PHP thinker : What would be an example of this? Lets suppose that currently I have a simple RecordForm class, and in its init() I am doing redirect after lines where I check record update was successfull.
    Jaka JanĨar : Actually Zend_Form isn't a model. It's a controller + view. I'd say it's similar to a TextInput in a desktop application. It does some displaying (view) and some validation (controller for the TextInput only, not an action controller).
    X-Istence : Zend_Form does not do any displaying, there are helpers in Zend_View that present the form to the world.

0 comments:

Post a Comment