php - Invalid factory registered Zend Framework 2 tutorial and everything seems to be in place -
here's module/blog/config/module.config.php
<?php return array( 'service_manager' => array( 'invokables' => array( 'blog\service\postserviceinterface' => 'blog\service\postservice' ) ), 'controllers' => array( 'factories' => array( 'blog\controller\list' => 'blog\controller\listcontrollerfactory' ) ), 'router' => array( // open configuration possible routes 'routes' => array( // define new route called "post" 'post' => array( // define routes type "zend\mvc\router\http\literal", string 'type' => 'literal', // configure route 'options' => array( // listen "/blog" uri 'route' => '/blog', // define default controller , action called when route matched 'defaults' => array( 'controller' => 'blog\controller\list', 'action' => 'index', ) ) ) ) ), 'view_manager' => array( 'template_path_stack' => array( __dir__ . '/../view', ), ) );
here's module/blog/src/blog/controller/listcontroller.php
<?php namespace blog\controller; use blog\service\postserviceinterface; use zend\mvc\controller\abstractactioncontroller; use zend\view\model\viewmodel; class listcontroller extends abstractactioncontroller { protected $postservice; public function __construct(postserviceinterface $postservice) { $this->postservice = $postservice; } public function indexaction() { return new viewmodel(array( 'posts' => $this->postservice->findallposts() )); } }
here's module/blog/src/blog/factory/listcontrollerfactory.php
<?php namespace blog\factory; use blog\controller\listcontroller; use zend\servicemanager\factoryinterface; use zend\servicemanager\servicelocatorinterface; class listcontrollerfactory implements factoryinterface { public function createservice(servicelocatorinterface $servicelocator) { $realservicelocator = $servicelocator->getservicelocator(); $postservice = $realservicelocator->get('blog\service\postserviceinterface'); return new listcontroller($postservice); } }
finally, here module/blog/module.php
<?php namespace blog; use zend\modulemanager\feature\configproviderinterface; use zend\modulemanager\feature\autoloaderproviderinterface; use codegenerationutils\autoloader\autoloaderinterface; class module implements configproviderinterface,autoloaderproviderinterface { public function getconfig() { return include __dir__ . '/config/module.config.php'; } public function getautoloaderconfig() { return array( 'zend\loader\standardautoloader' => array( 'namespaces' => array( // autoload classes namespace 'blog' '/module/blog/src/blog' __namespace__ => __dir__ . '/src/' . __namespace__, ) ) ); } }
i getting error:
while attempting create blogcontrollerlist(alias: blog\controller\list) invalid factory registered instance type.
not sure whats wrong here seems in place.
in config point blog\controller\listcontrollerfactory
while file in blog\factory\listcontrollerfactory
.
update , work:
'controllers' => array( 'factories' => array( 'blog\controller\list' => 'blog\factory\listcontrollerfactory' ) )
Comments
Post a Comment