Zend Framework 3教程路由和控制器

时间:2018-07-27 04:57:01

标签: php zend-framework

我正在尝试为Zend Framework 3编写教程。到达本页末尾(https://docs.zendframework.com/tutorials/getting-started/database-and-models/),当我进入localhost:8090时出现以下错误:

[ 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中注释掉“专辑”,它将加载基本框架。我的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.php(175):Zend \ ModuleManager \ ModuleManager-> loadModuleByName(Object(Zend \ ModuleManager \ ModuleEvent))

1 /cygdrive/c/users/kafka/dropbox/zf-tutorial/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(97):Zend \ ModuleManager \ ModuleManager-> loadModule('Album')< / h1>

2 /cygdrive/c/users/kafka/dropbox/zf-tutorial/vendor/zendframework/zend-eventmanager/src/EventManager.php(322):Zend \ ModuleManager \ ModuleManager-> onLoadModules(Object(Zend \ ModuleManager \ ModuleEvent))

3 /cygdrive/c/users/kafka/dropbox/zf-tutorial/vendor/zendframework/zend-eventmanager/src/EventManager.php(171):Zend \ EventManager \ EventManager-> triggerListeners(Object(Zend \ ModuleManager \ ModuleEvent))

4 /cygdrive/c/users/kafka/dropbox/zf-tutorial/vendor/zendframework/zend-modulemanager/src/ModuleManager.php中的/ cygdrive / c / users / kaf

1 个答案:

答案 0 :(得分:-1)

我在这里发现了问题,只是语法。因此,谢谢蒂姆·芳特,但不需要其他帮助。