>
> I typically add a "getForm()" method to my controller to instantiate and
> return the form:
>
> protected $_form;
>
> public function getForm()
> {
> if (null === $this->_form) {
> $this->_form = new My_Form_SomeFunctionalityINeedAFormFor();
> $this->_form->setAction(...)
> ->setMethod('post');
> }
> return $this->_form;
> }
>
> Then, in my actions, I retrieve it:
>
> public function formAction()
> {
> $this->view->form = $this->getForm();
> }
>
> public function processAction()
> {
> $request = $this->getRequest();
> if (!$request->isPost()) {
> return $this->_forward('form');
> }
>
> $form = $this->getForm();
> if (!$form->isValid($request->getPost())) {
> return $this->render('form');
> }
>
> // process and redirect ...
> }
>
> --
> Matthew Weier O'Phinney
> Software Architect | matthew@zend.com
> Zend Framework | http://framework.zend.com/
>
>
--
View this message in context: http://www.nabble.com/Passing-Zend-Form-instances-around-in-a-controller-for-validation-tp19243691p19244651.html
Sent from the Zend MVC mailing list archive at Nabble.com.
没有评论:
发表评论