2008年8月17日星期日

Re: [fw-mvc] Setting a custom parameter for a form

First off, init is called when the form is instantiated and so setting the
count after the form has been instantiated results in the protected property
rowCount being set and nothing more. Someone else can chime in if there is a
better solution but there are at least a couple of possible solutions,
depending upon your needs:

1. Pass the count to init directly instead of calling setCount after the
form has been instantiated

2. Move the loop into a separate method in which case you may also need to
set the order property of the elements so that the form elements display in
the correct order. Also, you want to consider creating a DisplayGroup for
each row so as to be able to easily reference a given row.

Hope that helps. If not maybe someone else will have some ideas.


Gordon Ross-8 wrote:
>
> I have a sample form of:
>
> class DummyForm extends Zend_Form
> {
> protected $rowCount;
>
> public function setCount($newCount)
> {
> if ($newCount>0)
> $this->rowCount = $newCount;
> }
>
> public function init()
> {
> $this->setName('dummy');
> $sf = new Zend_Form_SubForm();
>
> for($row=1; $row <= $this->rowCount; $row++)
> {
> $id = new Zend_Form_Element_Hidden('id');
> $number = new Zend_Form_Element_Text('number');
> $name = new Zend_Form_Element_Text('name');
> $rowForm = new Zend_Form_SubForm();
> $rowForm->addElements(array($id, $number, $name));
> $rowForm->setElementDecorators(array('ViewHelper', array('HtmlTag',
> array('tag' => 'td')),));
> $sf->addSubForm($rowForm, $row);
> }
> More code here to finish form assembly....
> }
>
> In my controller I do:
>
> $form = new DummyForm();
> $form->setCount('2');
> $this->view->form = $form;
>
>
> However, the form is being generated too soon and my call to
> $form->setCount is being ignored.
>
> What do I need to change for me to be able to set $rowCount correctly ?
>
> Thanks,
>
> GTG
>
>

--
View this message in context: http://www.nabble.com/Setting-a-custom-parameter-for-a-form-tp19018020p19019532.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: