1
我創建了擴展Zend_Form的新類,但是當我正嘗試通過我的新的自定義表單所有元素迭代(或僅僅指望他們全部)的結果始終爲0。自定義表單1.12
class Application_Form_ZendForm extends Poroform_Form {
public function init() {
parent::init();
$this->setAttrib('id', 'contact-form');
$this->addElement('text', 'textt', array(
'label' => 'Foo',
'value' => 'test',
"attribs" => array(
"icon" => "icon-append fa fa-user",
"section" => "col col-6"
),
));
}
}
class Poroform_Form extends Zend_Form {
public function __construct($options = null) {
parent::__construct($options);
}
public function init() {
$this->setAttrib("class", "smart-form");
$this->setAttrib("novalidate", "novalidate");
$this->setAttrib("elem_count", count($this->getElements())); //why is result 0?
$this->addElementPrefixPath('Poroform_Form_Decorator_', '/Poroform/Form/Decorator/', 'decorator');
$this->setElementDecorators(Array('SmartadminInput'));
foreach ($this->getElements() as $element) { //not working
$element->setAttrib("test", "aaa");
}
}
}
所以我在找錯方的自定義表單?
Thx for replay David。在'Poroform_Form :: init()'的開頭添加'parent :: init()'並不能解決問題。實際上,我通過在'Poroform_Form :: __ construct()'開頭添加'$ this-> init();'來解決它。 – porosman