module.php 中未找到 ZF3 控制器
ZF3 controller not found in module.php
我是 Zend Fw 3 的新手。
我关注了 https://docs.zendframework.com/tutorials/
我在 module.php
中添加了控制器配置
public function getControllerConfig(){
return[
'factories' = >[
Controller\DocumentController::class = > function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
通过运行这个,我遇到了这个错误:
<?php
namespace Document;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig()
{
return [
'factories' => [
Model\DocumentTable::class => function($container) {
$tableGateway = $container->get(Model\DocumentTableGateway::class);
return new Model\DocumentTable($tableGateway);
},
Model\DocumentTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Document());
return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\DocumentController::class => function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
}
尝试如下实施 AutoloaderProviderInterface
:
<?php
namespace Document;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements ConfigProviderInterface, AutoloaderProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig()
{
return [
'factories' => [
Model\DocumentTable::class => function($container) {
$tableGateway = $container->get(Model\DocumentTableGateway::class);
return new Model\DocumentTable($tableGateway);
},
Model\DocumentTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Document());
return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\DocumentController::class => function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
public function getAutoloaderConfig()
{
return [
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__,
],
],
];
}
}
您可能需要更改 __NAMESPACE__ => __DIR__
行中的路径,具体取决于您使用的目录结构和 Module.php
文件的位置。
我是 Zend Fw 3 的新手。 我关注了 https://docs.zendframework.com/tutorials/ 我在 module.php
中添加了控制器配置public function getControllerConfig(){
return[
'factories' = >[
Controller\DocumentController::class = > function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
通过运行这个,我遇到了这个错误:
<?php
namespace Document;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
class Module implements ConfigProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig()
{
return [
'factories' => [
Model\DocumentTable::class => function($container) {
$tableGateway = $container->get(Model\DocumentTableGateway::class);
return new Model\DocumentTable($tableGateway);
},
Model\DocumentTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Document());
return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\DocumentController::class => function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
}
尝试如下实施 AutoloaderProviderInterface
:
<?php
namespace Document;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\TableGateway;
use Zend\ModuleManager\Feature\ConfigProviderInterface;
use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
class Module implements ConfigProviderInterface, AutoloaderProviderInterface
{
public function getConfig()
{
return include __DIR__ . '/../config/module.config.php';
}
public function getServiceConfig()
{
return [
'factories' => [
Model\DocumentTable::class => function($container) {
$tableGateway = $container->get(Model\DocumentTableGateway::class);
return new Model\DocumentTable($tableGateway);
},
Model\DocumentTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Document());
return new TableGateway('document', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\DocumentController::class => function($container) {
return new Controller\DocumentController(
$container->get(Model\DocumentTable::class)
);
},
],
];
}
public function getAutoloaderConfig()
{
return [
'Zend\Loader\StandardAutoloader' => [
'namespaces' => [
__NAMESPACE__ => __DIR__,
],
],
];
}
}
您可能需要更改 __NAMESPACE__ => __DIR__
行中的路径,具体取决于您使用的目录结构和 Module.php
文件的位置。