Zend表单元素注释

时间:2011-09-12 02:13:47

标签: zend-framework zend-form zend-form-element

我为html内容构建了一个zend表单元素(一般注释)。

class Sistema_Form_Note extends Zend_Form_Element_Xhtml {

    public $helper = 'formNote';

    public function isValid($value){
        return true;
    }

}

它工作正常但它作为一个字段,当我在我的数据库中插入发布数据时,会出现索引注释元素。

POST array('name' => 'John'
  'note1' => ...); 

如何在不使用控制器上的removeElement()方法的情况下将其删除?有没有办法告诉班级它不应该是“db field”?

由于

3 个答案:

答案 0 :(得分:4)

我想通了,看看如何删除提交按钮,可以解决overring contruct方法并将ignore选项传递为true。

class Sistema_Form_Note extends Zend_Form_Element_Xhtml {

    public $helper = 'formNote';

    public function __construct($spec, $options = null)
    {
       if (is_string($spec) && ((null !== $options) && is_string($options))) {
            $options = array('label' => $options);
       }

       if (!isset($options['ignore'])) {
            $options['ignore'] = true;
       }

       parent::__construct($spec, $options);
    }

    public function isValid($value){
       return true;
    }

}

答案 1 :(得分:2)

我创建了一个具有相同要求的类似元素。我知道你已经回答了这个问题,但是我的解决方法是阻止值被发布数据覆盖(如果你使用$_value属性)。

class My_Form_Element_Note extends Zend_Form_Element_Xhtml
{
    public $helper = 'formNote';

    protected $_ignore = true;

    public function setValue($value)
    {
        if (null === $this->_value) {
            parent::setValue($value);
        }
        return $this;
    }
}

答案 2 :(得分:0)

对我而言,它有所帮助:

class App_Form_Element_Note扩展了Zend_Form_Element_Xhtml {

public $helper = 'formHtml';

public function __construct($spec, $options = null) {

     parent::__construct($spec, $options);
     $this->setIgnore(true);
}

public function isValid($value){
      return true;
}

}

“IsValid”功能的覆盖使得当验证器动作时会出现注释。