Php 以zend格式重写setValue
我希望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();
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()
函数