zend框架中的一个模块中的多个控制器

dec*_*ohn 3 php zend-framework2

嗨,我是zend framework2.2.0的新手.我想用多个控制器创建一个模块我从github下载"相册"模块并且它工作正常现在我想在其中添加更多控制器我已经在模块中显示了我的文件夹结构

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
Run Code Online (Sandbox Code Playgroud)

我还更改了文件中的所有名称空间

namespace Album\Controller;

class UserController extends\Zend\Mvc\Controller\AbstractActionController

和一些indexAction方法返回一个新的\ Zend\View\Model\ViewModel();

然后你可以在中创建你的视图文件

相册/视图/相册/用户/ index.phtml我做了以上更改."Album/Module.php"文件中是否需要任何chage?你能告诉我通过哪个链接可以看到用户列表?

我厌倦了这个错误,帮助我摆脱它

在此输入图像描述

kul*_*boj 9

您可能需要在Album/config文件夹中的module.config.php中为用户添加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',
                ),
            ),
        ),
    ),
),
Run Code Online (Sandbox Code Playgroud)

'controllers' => array(
    'invokables' => array(
        'Album\Controller\Album' => 'Album\Controller\AlbumController',
        'Album\Controller\User' => 'Album\Controller\UserController',
    ),
),
Run Code Online (Sandbox Code Playgroud)