2011-09-12 6 views
1

私はhtmlコンテンツ用のzendフォーム要素(一般的なメモ)を構築しました。Zend Form要素備考

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フィールド"ではないはずのことを伝える方法はありますか?

おかげ

答えて

4

が、私はボタンが削除された提出方法を探して、考え出し、それはoverringのcontruct方法と受け渡しを解決することができる真としてオプションを無視します。

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; 
    } 
} 
+0

グレート解決策 – dextervip

0

ちょうどそれが役立っている: 'は、IsValid' 関数の

クラス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; 
} 

}

overwrideは時にバリのノートが表示されます作られました行為。