【问题标题】:routing in zendframework 2 is not workingzendframework 2 中的路由不起作用
【发布时间】:2013-12-11 10:30:50
【问题描述】:
/* Here is my module config */



'controllers' => array(
    'invokables' => array(
    'User\Controller\User' => 'User\Controller\UserController',
    ),
),

'router' => array(
    'routes' => array(

          'user' => array(
            'type' => 'Literal',
            'options' => array(
                'route'    => '/user',
                'defaults' => array(
                    'controller' => 'User\Controller\User',
                    'action'     => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(

                        ),
                    ),
                ),
            ),
        ),
    ),
),

和控制器一样

类 UserController 扩展 AbstractActionController{

public function indexAction(){
    parent::indexAction();
    return new ViewModel();
}

public function addAction(){
    return new ViewModel();
}

}

每当我尝试访问 zf.localhost/user/user/add 时

它会抛出错误

找不到页面。

请求的控制器无法映射到现有的控制器类。

控制器: 用户(解析为无效的控制器类或别名:用户)

没有可用的例外

我不知道为什么路由不起作用。

【问题讨论】:

    标签: php zend-framework zend-framework2


    【解决方案1】:

    您正在尝试访问不存在的名为用户的控制器。你有两个选择:

    1. 'route' => '/[:controller][/:action]' 更改为'route' => '/:action'。它会在你的 User\Controller\UserAction 中搜索一个动作
    2. 添加到controllers 新别名'aliases' => array('user' => 'User\Controller\User')

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2016-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-06
      • 2014-03-25
      相关资源
      最近更新 更多