2013-12-11 28 views
0
/* 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(

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

和控制器作为路由在zendframework 2不工作

类UserController中延伸AbstractActionController {

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

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

}

每当我尝试访问zf.localhost /用户/用户/ add

它会抛出错误为

找不到页面。

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

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

例外,我想不通为什么路由不工作。

回答

1

您正试图访问不存在的控制器命名用户。您有两种选择:

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