嗨,我是 zend framework2.2.0 的新手。我想创建一个带有多个 Controller 的模块 我已经从 github 下载了“Album”模块并且工作正常 现在我想在其中添加更多 Controller 下面我展示了模块中文件的文件夹结构
module/
Album/
config/
module.config.php
src/
Album/
Controller/
AlbumController.php
UserController.php
Form/
AlbumForm.php
UserForm.php
Model/
AlbumTable.php
Album.php
UserTable.php
User.php
view/
album/
album/
index.phtml
user/
index.phtml
我还更改了文件中的所有 namespace
命名空间Album\Controller;
类 UserController 扩展\Zend\Mvc\Controller\AbstractActionController
一些 indexAction 方法返回一个新的\Zend\View\Model\ViewModel();
然后你可以创建你的 View 文件
相册/ View /相册/用户/index.phtml 我做了以上更改。 “Album/Module.php”文件中是否需要任何更改? 你能告诉我通过哪个链接可以看到用户列表吗?
我厌倦了这个错误帮助我摆脱它
最佳答案
您可能需要在 Album/config 文件夹中的 module.config.php 中为用户添加 url 规则。然后你可以像这样访问 url
// The following section is new and should be added to your file
'router' => array(
'routes' => array(
'album' => 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\Controller\Album',
'action' => 'index',
),
),
),
'user' => array(
'type' => 'segment',
'options' => array(
'route' => '/user[/:action][/:id]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'Album\Controller\User',
'action' => 'index',
),
),
),
),
),
还有
'controllers' => array(
'invokables' => array(
'Album\Controller\Album' => 'Album\Controller\AlbumController',
'Album\Controller\User' => 'Album\Controller\UserController',
),
),
关于php - zend 框架中一个模块中的多个 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16932781/