In a Zend Framework 2 Module.php the getFilterConfig() method is never called -
i have generic module in zend framework 2 application filters in it.
for entity created filter class inputfilterawareinterface:
public function getinputfilter() { if (!$this->inputfilter) { $inputfilter = new inputfilter(); $factory = new inputfactory(); $inputfilter->add( $factory->createinput( array( 'name' => 'desc', 'required' => false, 'filters' => array( array('name' => 'myfilter'), ), ) ) ); $this->inputfilter = $inputfilter; } return $this->inputfilter; }
to load myfilter implemented generic's module.php filterproviderinterface:
public function getfilterconfig() { // breakpoint @ next line return array( 'factories' => array( 'myfilter' => function($sl) { $myfilter = $sl->getservicelocator()->get('myfilterfactory'); return new filter\filter\myfilter($myfilter); }, ), ); }
when run application exception thrown:
zend\servicemanager\exception\servicenotfoundexception zend\filter\filterpluginmanager::get unable fetch or create instance myfilter
i ran debugger , realized getfilterconfig() method never called, because breakpoint not triggered.
what need insert in code filter config loaded?
edit:
the code executed debugger not stop @ breakpoint. when insert additional statement , set breakpoint this, execution stops.
in controller following
$servicemanager = $this->getservicelocator(); $filtermanager = $servicemanager->get('filtermanager');
and within filter manager have myfilter in factories array. still exception.
how zend\inputfilter\factory (as inputfactory) know filter factory?
finally figured out went wrong , how solve this:
within zend\inputfilter\factory used inputfactory defaultfilterchain created scratch generates new filterpluginmanager not service manager's filters.
to solve insert factory entity filter service manager injects defaultfilterchain filters of service manager:
'entityfilter' => function($sm) { $filtermanager = $sm->get('filtermanager'); $filterchain = new filterchain; $filterchain->setpluginmanager($filtermanager); return new entityfilter($filterchain); }
within getinputfilter method of filter class entityfilter inserted inputfactory:
$factory = new inputfactory(); $factory->setdefaultfilterchain($this->defaultfilterchain);
now inputfactory can use these filters of service manager's filter manager includes myfilter.
Comments
Post a Comment