我尝试在我的一个模块中创建一个新的路由,以对应于我的项目中的一个新的控制器。
但是我得到了这个错误,我不知道它来自哪里:
在尝试创建shop Management ementControlershop Management(别名:ShopManagement\Controller\ShopManagement)时,为该实例类型注册了无效的工厂。
我得到了这个StackTrace:
0/var/www/routedudrive。fr/vendor/zendframework/zend servicemanager/src/servicemanager。php(634):Zend\ServiceManager\AbstractPluginManager-
1 /var/www/routedudrive.fr/vendor/zendframework/zend-servicemanager/src/ServiceManager.php(597):Zend\ServiceManager\ServiceManager-
2/var/www/routedudrive。fr/vendor/zendframework/zend servicemanager/src/servicemanager。php(530):Zend\ServiceManager\ServiceManager-
3/var/www/routedudrive。fr/vendor/zendframework/zend servicemanager/src/AbstractPluginManager。php(161):Zend\ServiceManager\ServiceManager-
4/var/www/routedudrive。fr/vendor/zendframework/zend mvc/src/DispatchListener。php(94):Zend\ServiceManager\AbstractPluginManager-
5【内部函数】:Zend\Mvc\DispatchListener-
7 /var/www/routedudrive.fr/vendor/zendframework/zend-eventmanager/src/EventManager.php(263):Zend\EventManager\EventManager-
8/var/www/routedudrive。fr/vendor/zendframework/zend mvc/src/Application。php(340):Zend\EventManager\EventManager-
9/var/www/routedudrive。fr/公共/索引。php(21):Zend\Mvc\Application-
10{main}
这是我的模块。配置。php:
<?php
return array(
'controllers' => array(
'factories' => array(
'Backshop\Controller\Backshop' => Backshop\ControllerFactory\BackshopControllerFactory::class,
'Shopmanagement\Controller\Shopmanagement' => Shopmanagement\ControllerFactory\ShopmanagementControllerFactory::class,
),
),
'router' => array(
'routes' => array(
'backshop' => array(
'type' => 'segment',
'options' => array(
'route' => '/backshop[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9a-zA-Z]+',
),
'defaults' => array(
'controller' => 'Backshop\Controller\Backshop',
'action' => 'index',
),
),
),
'shopmanagement' => array(
'type' => 'segment',
'options' => array(
'route' => '/shopmanagement[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9a-zA-Z]+',
),
'defaults' => array(
'controller' => 'Shopmanagement\Controller\Shopmanagement',
'action' => 'index',
),
),
),
),
),
'view_manager' => array(
'template_path_stack' => array(
'backshop' => __DIR__ . '/../view',
'shopmanagement' => __DIR__ . '/../view',
),
),
);
这是我的ShopManagement ementControlllerFactory.php:
<?php
namespace Shopmanagement\ControllerFactory;
use Shopmanagement\Controller\ShopmanagementController;
use \Zend\ServiceManager\FactoryInterface;
use \Zend\ServiceManager\ServiceLocatorInterface;
class ShopmanagementControllerFactory implements FactoryInterface
{
public function createService(ServiceLocatorInterface $serviceLocator) {
$sm = $serviceLocator->getServiceLocator();
//$merchantTable = $sm->get('Backshop\Model\MerchantTable');
//$accountValidationTable = $sm->get('Backshop\Model\AccountValidationTable');
$controller = new ShopmanagementController();
return $controller;
}
}
这是我的店长。php:
<?php
namespace Shopmanagement\Controller;
use Zend\View\Model\ViewModel;
class ShopmanagementController extends AbstractActionController{
public function __construct()
{
}
public function indexAction(){
return new ViewModel();
}
}
这是我的文件树:
如果您知道问题出在哪里,所有帮助都将不胜感激:)
提前谢谢大家,,
托马斯
我终于找到了解决办法,如果它能帮助某人。
我只是忘记了在我的模块中引用我的名称空间。php文件如下所示:
public function getAutoloaderConfig()
{
return array(
'Zend\Loader\ClassMapAutoloader' => array(
__DIR__ . '/autoload_classmap.php',
),
'Zend\Loader\StandardAutoloader' => array(
'namespaces' => array(
__NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
'Shopmanagement' => __DIR__ . '/src/' . 'Shopmanagement', //This line
),
),
);
}