Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 以zend格式重写setValue_Php_Oop_Zend Form - Fatal编程技术网

Php 以zend格式重写setValue

Php 以zend格式重写setValue,php,oop,zend-form,Php,Oop,Zend Form,我希望zend表单重写setValue函数,以便可以操纵给定给该函数的值。我如何实现这一点 我当前的表单结构如下所示: class My_Form_Login { public $Form; public $Username; public function __construct() { $this->Form = new Form_Abstract(); $this->init();

我希望zend表单重写setValue函数,以便可以操纵给定给该函数的值。我如何实现这一点

我当前的表单结构如下所示:

class  My_Form_Login   
{   
 public $Form;  
 public $Username;      
 public function  __construct()  
    {  
        $this->Form = new Form_Abstract();  
        $this->init();  
    }  
 public function init()  
    {  
     $this->Username ->setValue('100');  
    }  
}    

class Form_Abstract extends Zend_Form  
{  
    public function __construct($options = null)  
    {  
        parent::__construct($options);  
        $this->setDecorators(array(  'FormElements','FormErrors','Form' ));  
    }  

    public function setValue($value)
    {     
        $strippedValue = stripslashes($value);  
        return parent::setValue($strippedValue);  
    }
}

提前感谢。

您可以将Zend_表单扩展到自己的类中,如:

My_Form extends Zend_Form
{
  public function setValue($arg)
  {
    // My override code here
  }
}

然后直接使用这个类而不是Zend_表单

考虑改用Zend filter接口。比如说

class My_Filter_Stripslashes implements Zend_Filter_Interface
{
    public function filter($value)
    {
        return get_magic_quotes_gpc() ? $this->_clean($value) : $value;
    }

    protected function _clean($value)
    {
        return is_array($value) ? array_map(array($this, '_clean'), $value) : stripslashes($value);
    }
}
然后在添加元素后将其应用于元素

$form->setElementFilters(array(new My_Filter_Stripslashes));

您已经试过什么了吗?您需要使用:
$form=new My\u form
而不是
$form=new Zend\u form
,才能使用
setValue()
函数