doupao6698 2014-10-16 04:56
浏览 79

Zend Framework 2路由无法正常工作

how can i add a default home page in routing?

my route works when i access this url {myapp}/modulename/controllername but when i access this {myapp}/modulename it returns a 404.

How can i fix that?

return array(
    'controllers'   => array(
        'invokables'    => array(
            'Modulename\Controller\Mycontroller'     => 'Modulename\Controller\TheController',
        ),
    ),
    'router' => array(
         'routes' => array(
            'modulename' => array(
                'type'    => 'Literal',
                'options' => array(
                    'route'    => '/modulename',
                    'defaults' => array(
                        '__NAMESPACE__' => 'Modulename\Controller',
                        'controller'    => 'My',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    'thechild' => array(
                        'type'    => 'Segment',
                        'options' => array(
                            'route'    => '[/:controller][/:action][/:id]',
                            'constraints' => array(
                                    'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                    'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                                    'id'         => '[0-9]*',
                            ),
                            'defaults' => array( 
                                '__NAMESPACE__' => 'Modulename\Controller',
                                'controller'    => 'User',
                                'action'        => 'index',
                            ),
                        ),
                    ),
                ),
            ), 
         ),
     ),  


        'view_manager'  => array(
            'template_path_stack' => array(
                'users' => __DIR__.'/../view',
            ),
            'display_exceptions' => true,
        ),
    );
  • 写回答

3条回答 默认 最新

  • douyan4243 2014-10-16 05:44
    关注
    'Modulename\Controller\Mycontroller'     => 'Modulename\Controller\TheController',
    

    Here you used the controller name is 'TheController'

       'defaults' => array(
                        '__NAMESPACE__' => 'Modulename\Controller',
                        'controller'    => 'My',
                        'action'        => 'index',
                    ),
    

    But here you specified controller name 'My'.

    Change here 'controller' => 'The', and check

    If your controller name is "UserController" then change

    'Modulename\Controller\Mycontroller'     => 'Modulename\Controller\TheController',
    
     as
    
    'Modulename\Controller\User'     => 'Modulename\Controller\UserController', 
    
     and 
    
    'defaults' => array(
                        '__NAMESPACE__' => 'Modulename\Controller',
                        'controller'    => 'My',
                        'action'        => 'index',
                    ),
    
      as
    
    'defaults' => array(
                        '__NAMESPACE__' => 'Modulename\Controller',
                        'controller'    => 'User',
                        'action'        => 'index',
                    ),
    

    And change this(at after 'may_terminate')

    'defaults' => array( 
                        '__NAMESPACE__' => 'Modulename\Controller',
                        'controller'    => 'User',
                        'action'        => 'index',
                        ),
                            ),
    
    as
    
    'defaults' => array(),
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)