我尝试使用一个Zend_窗体进行更新和创建,并希望通过一个参数同时进行切换。但是我使用构造函数的方法不起作用。调试此部分时,属性设置正确,但在in it()-方法中,属性再次为空。
也许我不理解Zend_形式的方法。你能帮助我吗?错误在哪里?
窗体类:
class Application_Form_User extends Zend_Form {
const CREATE = 'create';
const UPDATE = 'update';
protected $_formState;
public function __construct($options = null, $formState = self::CREATE) {
parent::__construct($options);
$this->_formState = $formState;
$this->setAction('/user/' . $this->_formState);
}
public function init() {
$this->setMethod(Zend_Form::METHOD_POST);
if ($this->_formState == self::CREATE) {
$password = new Zend_Form_Element_Password('password');
$password->setRequired()
->setLabel('Password:')
->addFilter(new Zend_Filter_StringTrim());
}
[..]
控制器操作中的用法:
$form = new Application_Form_User();
$this->view->form = $form->render();
谢谢您。