Php Zend Framework 3路由和控制器教程
我正在尝试为Zend Framework 3编写教程。在本页末尾,当我转到localhost:8090时,我得到以下错误:Php Zend Framework 3路由和控制器教程,php,zend-framework,Php,Zend Framework,我正在尝试为Zend Framework 3编写教程。在本页末尾,当我转到localhost:8090时,我得到以下错误: [ Model\AlbumTable::class => function($container) { $tableGateway = $container->get(Model\AlbumTableGateway::class); return new Model\AlbumTable($tableGateway); }, Model\AlbumTableGa
[ Model\AlbumTable::class => function($container) { $tableGateway = $container->get(Model\AlbumTableGateway::class); return new Model\AlbumTable($tableGateway); }, Model\AlbumTableGateway::class => function ($container) { $dbAdapter = $container->get(AdapterInterface::class); $resultSetPrototype = new ResultSet(); $resultSetPrototype->setArrayObjectPrototype(new Model\Album()); return new TableGateway('album', $dbAdapter, null, $resultSetPrototype); }, ], ]; } public function getControllerConfig() { return [ 'factories' => [ Controller\AlbumController::class => function($container) { return new Controller\AlbumController( $container->get(Model\AlbumTable::class) ); }, ], ]; } }
如果我在module.config.php中注释掉'Album',它将加载基本框架。我的composer.json文件具有Album\:module/Album/src/并且我运行了$composer dump autoload
我检查了所有的东西,不知道出了什么问题。如有任何建议,将不胜感激,谢谢
namespace Album;
use Zend\Router\Http\Segment;
return [
'router' => [
'routes' => [
'album' => [
'type' => Segment::class,
'options' => [
'route' => '/album[/:action[/:id]]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\AlbumController::class,
'action' => 'index',
],
],
],
],
],
'view_manager' => [
'template_path_stack' => [
'album' => __DIR__ . '/../view',
],
],
];
<? php
namespace Album;
use Zend\Db\Adapter\AdapterInterface;
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\AlbumTable::class => function($container) {
$tableGateway = $container->get(Model\AlbumTableGateway::class);
return new Model\AlbumTable($tableGateway);
},
Model\AlbumTableGateway::class => function ($container) {
$dbAdapter = $container->get(AdapterInterface::class);
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new Model\Album());
return new TableGateway('album', $dbAdapter, null, $resultSetPrototype);
},
],
];
}
public function getControllerConfig()
{
return [
'factories' => [
Controller\AlbumController::class => function($container) {
return new Controller\AlbumController(
$container->get(Model\AlbumTable::class)
);
},
],
];
}
}
我还收到以下错误消息:
127.0.0.1:52590[500]:/-未捕获Zend\ModuleManager\Exception\RuntimeException:无法初始化模块相册。在/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend modulemanager/src/modulemanager.php:203中
堆栈跟踪:
0/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend modulemanager/src/modulemanager.php175:zend\modulemanager\modulemanager->loadModuleByNameObjectZend\modulemanager\ModuleEvent
1/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend modulemanager/src/modulemanager.php97:zend\modulemanager\modulemanager->loadModule'Album'
2/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend eventmanager/src/eventmanager.php322:zend\ModuleManager\ModuleManager->onload模块对象zend\ModuleManager\ModuleEvent
3/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend eventmanager/src/eventmanager.php171:zend\eventmanager\eventmanager->triggerListenersObjectZend\ModuleManager\ModuleEvent
4/cygdrive/c/users/kaf in/cygdrive/c/users/kafka/dropbox/zf tutorial/vendor/zendframework/zend modulemanager/src/modulemanager.php第203行我在这里发现了问题,只是语法问题。所以,谢谢蒂姆·福兰克,但不需要更多的帮助 您发布的不是错误,而是服务配置函数的内容。在什么情况下你会看到这个?我正在尝试Zend Framework 3教程。我已经完成了这些页面:模块、路由和控制器、数据库和模型。此时,我应该能够在输入url时看到相册模块。但是,我在浏览器中收到上面发布的消息。我也看到了我在上面发布的错误。