层板配置模块路由

时间:2020-04-27 14:20:10

标签: module laminas

我已经开始了有关层流的最新教程。

名为Provider的新模块的路由不起作用

发生404错误 网页未找到。 路由无法匹配请求的URL。

  • 查看我的Module.php代码后,我会看到:

getConfig()不被调用

getServiceConfig()和getControllerConfig()是。

在应用程序模块中的

getConfig也未调用

<?php

namespace Provider;

use Laminas\Db\Adapter\AdapterInterface;
use Laminas\Db\ResultSet\ResultSet;
use Laminas\Db\TableGateway\TableGateway;

use Laminas\ModuleManager\Feature\AutoloaderProviderInterface;
use Laminas\ModuleManager\Feature\ConfigProviderInterface;


class Module implements ConfigProviderInterface, AutoloaderProviderInterface
{

    public function getConfig()
    {       

        die ("getConfig");

        return include __DIR__ . '/../config/module.config.php';
    }

    public function getAutoloaderConfig()
    {   

        //die ("getAutoloaderConfig");


        //return array(
        //      'Laminas\Loader\StandardAutoloader' => array(
        //              'namespaces' => array(
        //                      __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
        //              ),
        //      ),
        //);
    }


    public function getServiceConfig()
    {   

        //die ("getServiceConfig");


        return [
                'factories' => [
                        Model\ProviderTable::class => function($container) {
                        $tableGateway = $container->get(Provider\ProviderTableGateway::class);
                        return new Model\ProviderTable($tableGateway);
                    },
                    Model\ProviderTableGateway::class => function ($container) {
                        $dbAdapter = $container->get(AdapterInterface::class);
                        $resultSetPrototype = new ResultSet();
                        $resultSetPrototype->setArrayObjectPrototype(new Model\Album());
                        return new TableGateway('provider', $dbAdapter, null, $resultSetPrototype);
                    },
                    ],
                    ];
}


    public function getControllerConfig()
    {

        //die ("getControllerConfig");


        return [
            'factories' => [
                    Controller\ProviderController::class => function($container) {
                        return new Controller\ProviderController(
                                $container->get(Model\ProviderTable::class)
                                );
                    },
                    ],
                    ];
    }





}

3 个答案:

答案 0 :(得分:0)

您添加了路由器配置吗?

在上面的附加代码中,您具有以下功能:

public function getConfig()
    {       

        //die ("getConfig");  // BE SURE YOU REMOVE THIS LINE

        return include __DIR__ . '/../config/module.config.php';
    }

它是包含文件的其他设置。在此文件“ /../config/module.config.php”中,您应该添加路由器配置。它应该看起来像这样:

return [

// ...其他设置

    'router' => [
        'routes' => [
            // Literal route named "home"
            'home' => [
                'type' => 'literal',
                'options' => [
                    'route' => '/',
                    'defaults' => [
                        'controller' => 'Application\Controller\IndexController',
                        'action' => 'index',
                    ],
                ],
            ],
            // Literal route named "contact"
            'contact' => [
                'type' => 'literal',
                'options' => [
                    'route' => 'contact',
                    'defaults' => [
                        'controller' => 'Application\Controller\ContactController',
                        'action' => 'form',
                    ],
                ],
            ],
        ],
    ],
];

https://docs.laminas.dev/laminas-router/routing/#simple-example-with-two-literal-routes

答案 1 :(得分:0)

您需要启用开发模式。将composer development-enable运行到活动开发模式。

答案 2 :(得分:0)

也许 composer json 没有更新 (my-application/composer.json)

"autoload": {
    "psr-4": {
        "Application\\": "module/Application/src/",
        "Provider\\": "module/Provider/src/"
    }
},

更新自动加载类映射:

composer dump-autoload

https://docs.laminas.dev/tutorials/getting-started/modules/#autoloading