When using Zend_Form I find myself creating a lot of controller methods that look like this:
function editPersonAction()
{
$model = $this->getPersonModel();
$form = $this->getPersonEditForm();
if ($this->getRequest()->isPost() {
$data = $this->getRequest()->getPost();
//$form->populate($data); [removed in edit]
if ($form->isValid($data)) {
$data = $form->getValues();
$model->setFromArray($data);
// code to save model then decide which page to redirect to
}
} else {
$form->populate($model->toArray());
}
$this->view->form = $form;
}
Most of that code is always the same, and I'm sure there are better ways to do this. What other patterns do people use with Zend_Form to cut down on the amount of boilerplate code used?