zend framework2 - I need help about Input Filter -
i have method in 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'), ), ))); } homecoming $this->$inputfilter; }
then used in controller like
$taikhoan = new taikhoan();
$form->setinputfilter($taikhoan->getinputfilter());
when run, show me error
catchable fatal error: object of class zend\inputfilter\inputfilter not converted string in c:\wamp\www\zf\module\cpanel\src\cpanel\model\taikhoan.php on line 59
the problem typo in statement:
return $this->$inputfilter;
php interpreting line dynamic property name, , converting string. right version is:
return $this->inputfilter;
also need assign input filter:
public function getinputfilter() { if (!$this->inputfilter) { // ... $this->inputfilter = $inputfilter; } homecoming $this->inputfilter; }
zend-framework2 zend-inputfilter
No comments:
Post a Comment