Zend框架中一个模块中的多个控制器 [英] Multiple controller in one module in zend framework
问题描述
我是 zend framework2.2.0 的新手.我想创建一个带有多个控制器的模块 我已经从 github 下载了相册"模块并且它工作正常现在我想在其中添加更多控制器下面我展示了模块中文件的文件夹结构
hi i am new in zend framework2.2.0. i want to create one module with multiple controller i have download "Album" module from github and its working fine Now i want to add the more controller in it the below i have shown my folder structure for file in module
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
我也改变了文件中的所有命名空间
i have also changed all the name space in file
命名空间专辑\控制器;
namespace Album\Controller;
类 UserController 扩展 \Zend\Mvc\Controller\AbstractActionController
class UserController extends \Zend\Mvc\Controller\AbstractActionController
和一些 indexAction 方法女巫返回一个新的 \Zend\View\Model\ViewModel();
and some indexAction method witch returns a new \Zend\View\Model\ViewModel();
然后你可以在
相册/视图/相册/用户/index.phtml我做了上述更改.Album/Module.php"文件中是否需要修改?你能告诉我通过哪个链接我可以看到用户列表吗?
Album/view/Album/user/index.phtml i did above changes. is there any chage needed in "Album/Module.php" file ? can you tell me through which link i can see users list ?
我厌倦了这个错误帮助我摆脱它
i and tired with this error help me to get out of it
推荐答案
您可能需要在 Album/config 文件夹的 module.config.php 中为用户添加 url 规则.然后你可以像
You may need to add url rules for user in module.config.php in Album/config folder. Then you can access the url like
// 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',
),
),
这篇关于Zend框架中一个模块中的多个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!