【问题标题】:Zend Form Element NotesZend 表单元素注释
【发布时间】:2011-09-12 02:13:47
【问题描述】:

我已经为 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() 方法的情况下删除它?有什么方法可以告诉类它不应该是“数据库字段”吗?

谢谢

【问题讨论】:

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


    【解决方案1】:

    我想通了,看看提交按钮是如何被删除的,它可以解决覆盖构造方法并将忽略选项传递为 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;
        }
    
    }
    

    【讨论】:

      【解决方案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;
          }
      }
      

      【讨论】:

        【解决方案3】:

        对我来说只是帮助:

        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' 函数的覆盖使得该注释在验证器动作时出现。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-05-24
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多