我遇到了这个问题:我希望将形式传递给我的形式,因为我需要它来完成选择。
这是我的代码
控制器:
$p1 = $this->getRequest()->getParam ( '1' );
$p2 = $this->getRequest()->getParam ( '2' );
$utentepost = new Application_Model_myMapper();
$data = $utentepost->populateFormInsert($p1, $p2);
$form = new Application_Form_myForm();
$form->populate($data);
...
表格
public function init() {
$this->setMethod('post');
$this->addElement('text', 'p1', array());
$this->addElement('text', 'p2', array());
$this->addElement('select', 'sede_id', array(
'label' => 'Sede',
'required' => true,
'multiOptions' => $this->_setSelect($p1),
));
.... ....
protected function _setSelect($p1) {
... call model/mapper to execute sql query
}
由于
答案 0 :(得分:1)
您可以执行以下操作:
如果您在表单中定义了构造函数,请添加“parent :: ..”:
public function __construct($options = null)
{
parent::__construct($options);
}
现在将attribs作为数组传递给您的表单:
$form = new Application_Form_myForm(array('p1' => $p1, 'p2' => $p2));
在表单中:
protected function _setSelect() {
$p1 = $this->getAttrib('p1');
... call model/mapper to execute sql query
}