2008年8月17日星期日

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

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

没有评论: