路线名称"当然"没找到,zend框架2

时间:2014-05-21 16:45:57

标签: zend-framework2

我无法解决这个问题...我是zend的新手,这是zend

的修改示例
  

Zend \ Mvc \ Router \ Exception \ RuntimeException文件:C:\ wamp \ www \ test \ vendor \ zendframework \ zendframework \ library \ Zend \ Mvc \ Router \ Http \ TreeRouteStack.php:317   信息:   未找到名称“课程”的路线

这是我的module.config.php

<?php 

return array(
 'controllers' => array(
      'invokables' => array(
         'Course\Controller\Index' => 'Course\Controller\IndexController',
        ),  ),
    'router' => array(
         'routes' => array(
           'index' => array(
                 'type' => 'Literal',
                     'options' => array(
                     'route' => '/course',
                     'defaults' => array(
                         'controller' => 'Course\Controller\Index',
                         'action'     => 'index'
                     ),
                 ),
             ),
         )
     ),
                'view_manager' => array(
     'template_path_stack' => array(
         'course' => __DIR__ . '/../view/'
     ),
     )


 );

和IndexController.php

    <?php 

namespace Course\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;

class IndexController extends AbstractActionController{   

    protected $courseTable;


public function indexAction()
    {
     return new ViewModel(array(
             'courses' => $this->getCourseTable()->fetchAll(),
         ));
    }

    public function getCourseTable()
     {
         if (!$this->courseTable) {
             $sm = $this->getServiceLocator();
             $this->courseTable = $sm->get('Course\Model\CourseTable');
         }
         return $this->courseTable;
     }
}
请各位帮帮我,因为我不知道这有什么问题。

2 个答案:

答案 0 :(得分:1)

您的配置定义了一条名为 index 的路线。如果您希望将其命名为&#39; course&#39;,则需要重命名。我在配置中突出显示了路径名称:

'router' => array(
     'routes' => array(
       'index' => array( // <-- this array key is the route name
             'type' => 'Literal',
                 'options' => array(
                 'route' => '/course',
                 'defaults' => array(
                     'controller' => 'Course\Controller\Index',
                     'action'     => 'index'
                 ),
             ),
         ),
     )
 ),

答案 1 :(得分:0)

对我来说,问题是我没有在/config/modules.config.php中注册新创建的模块