douyinglan2599
2013-06-05 06:15
浏览 46
已采纳

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

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;

class UserController extends \Zend\Mvc\Controller\AbstractActionController

and some indexAction method witch returns a new \Zend\View\Model\ViewModel();

then you can create your viewfile in

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

enter image description here

图片转代码服务由CSDN问答提供 功能建议

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

  module / 
 Album / 
 config / 
 module.config.php 
 src / 
 Album / 
 Controller / 
 AlbumController.php 
 UserController.php \  n Form / 
 AlbumForm.php 
 UserForm.php 
 Model / 
 AlbumTable.php 
 Album.php 
 UserTable.php 
 User.php 
 
 view / 
 album / 
 album  / 
 index.phtml 
 user / 
 index.phtml 
   
 
 

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

namespace Album \ Contro ller;

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

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

然后您可以在

专辑/视图/专辑/用户/索引.phtml i中创建您的视图文件。 “Album / Module.php”文件中是否需要任何chage? 你能告诉我通过哪个链接我可以看到用户列表?

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

\ n

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • doutu4335 2013-06-05 06:24
    已采纳

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

    Also

    'controllers' => array(
        'invokables' => array(
            'Album\Controller\Album' => 'Album\Controller\AlbumController',
            'Album\Controller\User' => 'Album\Controller\UserController',
        ),
    ),
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题