views:

488

answers:

2

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?

+4  A: 
$redirector =
    Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
$redirector->gotoSimple('index','index');
vartec
+3  A: 

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.

troelskn
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.
PHP thinker
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).
Jaka Jančar
Zend_Form does not do any displaying, there are helpers in Zend_View that present the form to the world.
X-Istence