我在Model TaiKhoan中有这种方法
public function getInputFilter()
{
if (!$this->inputFilter)
{
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'TenTaiKhoan',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
)));
$inputFilter->add($factory->createInput(array(
'name' => 'MatKhau',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
)));
}
return $this->$inputFilter;
}
然后我在我的控制器中使用它
$taikhoan = new TaiKhoan();
$形式 - > setInputFilter($ taikhoan-> getInputFilter());
当我跑步时,它会显示此错误
Catchable fatal error: Object of class Zend\InputFilter\InputFilter could not be converted to string in C:\wamp\www\ZF\module\CPanel\src\CPanel\Model\TaiKhoan.php on line 59
答案 0 :(得分:1)
问题是这句话中的拼写错误:
return $this->$inputFilter;
PHP将此行解释为动态属性名称,并将其转换为字符串。正确的版本是:
return $this->inputFilter;
您还需要为输入过滤器指定一些内容:
public function getInputFilter()
{
if (!$this->inputFilter)
{
// ...
$this->inputFilter = $inputFilter;
}
return $this->inputFilter;
}
答案 1 :(得分:0)
您懒得加载输入过滤器,但从不设置$this->inputFilter
。
public function getInputFilter()
{
if (!$this->inputFilter)
{
$this->inputFilter = new InputFilter();
}
return $this->inputFilter;
}
不确定这是否是您的问题,因为错误是将输入过滤器转换为字符串。请提供TaiKhoan.php第59行的确切代码。