Module 薄板配置模块布线
我已经开始学习Laminas的最新教程 名为Provider的新模块的路由不工作 发生404错误 找不到页面。 路由无法匹配请求的URLModule 薄板配置模块布线,module,laminas,Module,Laminas,我已经开始学习Laminas的最新教程 名为Provider的新模块的路由不工作 发生404错误 找不到页面。 路由无法匹配请求的URL 在查看我的Module.php代码时,我看到: 未调用getConfig(),但 getServiceConfig()和getControllerConfig()是 应用程序模块中的getConfig也未调用 <?php namespace Provider; use Laminas\Db\Adapter\AdapterInterface; us
- 在查看我的Module.php代码时,我看到:
<?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)
);
},
],
];
}
}
是否添加了路由器配置
在上面附加的代码中,您具有以下功能:
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',
],
],
],
],
],
];
您需要启用开发模式,可以在中找到更多阅读资料。运行composer development enable
到活动开发模式。可能没有更新composer json(我的应用程序/composer.json)
更新自动加载类映射:
composer dump-autoload
我自己对Laminas MVC不熟悉。您很可能会在官方的Laminas论坛()中得到响应。路由器配置为:return include DIR.'//config/module.config.php';但这一行永远不会被调用,因为没有调用getConfig()。
composer dump-autoload