问题描述
我尝试遵循 Akrabats 教程 应用程序/索引正在运行,专辑部分不是.
I try to follow Akrabats Tutorial the Application/Index is working, the Album part not.
我也用 ZendSkeletonModule 尝试了它,但没有成功.
I tried it also with the ZendSkeletonModule with no luck.
两种情况下的错误是:
album/album(解析为无效的控制器类或别名:album/album)
我用 ZF2 master 和 beta4 标签尝试了它(但 beta4 标签给出了关于缺少方法 getEventManager 的 php 错误)
I tried it with ZF2 master and beta4 tag (but beta4 tag gives php error about missing method getEventManager)
我从 Akrabats 教程中获取了代码,之后使用了 GitHub Repo.不幸的是,没有一些论坛或评论部分可以寻求帮助.
I took the code from Akrabats Tutorial, and after that failed used the code form the GitHub Repo. Unfortunatly there isnt some Forum or Comment section to ask for help.
我在教程中发现了一些差异,而 module.config.php 中的 Skeleton(zfcUser 具有相同的差异)(我认为这是问题的核心).
I found some diffrences in the tutorial and the Skeleton (zfcUser has the same diffrence) in the module.config.php (which i believe is the core of the problem).
本教程在控制器索引中使用 classes
,zfcUser 和使用 invokables
的 Skeleton 但它似乎并不重要,因为错误不会改变.
The tutorial uses classes
in the controller index, zfcUser and the Skeleton using invokables
but it doesnt seem to matter, as the error dont change.
我的 module.config 目前看起来像这样:
my module.config currently looks like this:
<?php
return array(
// Controllers in this module
'controller' => array(
'invokables' => array(
'album/album' => 'Album\Controller\AlbumController',
),
),
// Routes for this module
'router' => array(
'routes' => array(
'album' => array(
'type' => 'Literal',
'priority' => 1000,
'options' => array(
'route' => '/album',
'defaults' => array(
'controller' => 'album/album',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'misc' => array (
'type' => 'segment',
'options' => array(
'route' => '/album/[:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'album/album',
'action' => 'index',
),
),
),
),
),
),
),
// View setup for this module
'view_manager' => array(
'template_path_stack' => array(
'album' => __DIR__ . '/../view',
),
),
);
专辑\控制器\专辑控制器:
Album\Controller\AlbumController:
<?php
namespace Album\Controller;
use Zend\Mvc\Controller\ActionController,
Zend\View\Model\ViewModel,
Album\Model\AlbumTable,
Album\Model\Album,
Album\Form\AlbumForm;
class AlbumController extends ActionController
{
// [....]
}
我不知道去哪里解决这个错误,你们中有人有什么想法吗?
I dont know where to look to fix this error, does someone of you have an idea?
除非另有说明,否则代码就像 github 上的原始代码(见上面的链接).
Code is like orginal on github (see links above) when not mentioned otherwise.
TIA
推荐答案
这里的区别不仅在于可调用项,还在于数组键现在是复数形式的controllers",至此我的诀窍.在您的代码中,invokables"已更改,但您似乎使用controller"作为键.
The difference here is not only the invokables, but also that the array key is now "controllers" in plural, wich did the trick for me. In your code "invokables" is already changed, but you seem to use "controller" as key.
'controllers' => array(
'invokables' => array(
'album/album' => 'Album\Controller\AlbumController',
),
),
这篇关于Zend Framework 2 MVC - 模块路由映射不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!