3

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

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

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

命名空间专辑\控制器;

类 UserController 扩展 \Zend\Mvc\Controller\AbstractActionController

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

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

Album/view/Album/user/index.phtml 我做了上述更改。“Album/Module.php”文件中是否需要任何更改?你能告诉我通过哪个链接我可以看到用户列表吗?

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

在此处输入图像描述

4

1 回答 1

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',
                ),
            ),
        ),
    ),
),

'controllers' => array(
    'invokables' => array(
        'Album\Controller\Album' => 'Album\Controller\AlbumController',
        'Album\Controller\User' => 'Album\Controller\UserController',
    ),
),
于 2013-06-05T06:24:08.417 回答