(on Wednesday, 17 December 2008, 11:08 AM +0100):
> Am Dienstag, den 16.12.2008, 09:09 -0500 schrieb Matthew Weier
> O'Phinney:
> [...]
> > BTW, Zend_Form can act like a parameter object as well. While much of
> > the value of Zend_Form comes from its ability to render itself, the fact
> > is that it is also at its heart an input filter. I've been attaching
> > models to my forms for a while now.
>
> That's an interesting approach. So you have MatthewForm extending
> Zend_Form and a typehint for MatthewForm in your domain model?
Correct, as well as an accessor for retrieving the form:
public function getBugForm()
{
if (null === $this->_bugForm) {
$this->_bugForm = new Module_Form_Bug();
}
return $this->_bugForm;
}
The basic technique is like this:
public function save(array $data)
{
$validator = $this->getBugForm();
if (!$validator->isValid($data)) {
return false;
}
$values = $validator->getValues();
// ...
}
However, you could also do this:
public function save(Module_Form_Bug $data)
{
$values = $data->getValues();
// ...
}
which would assume you've validated first, and simply be using the
filter chain capabilities of the form.
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论