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

  • 写回答

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',
        ),
    ),
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)