2
votes

I can't solve this problem... I'm new in zend and this is a modified example from zend

Zend\Mvc\Router\Exception\RuntimeException File: C:\wamp\www\test\vendor\zendframework\zendframework\library\Zend\Mvc\Router\Http\TreeRouteStack.php:317 Message: Route with name "course" not found

this is my 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/'
     ),
     )


 );

and 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;
     }
}

guys please help me, because I don't have any idea of what's wrong with this.

2

2 Answers

3
votes

Your config defines one route, called index. If you want it to be called 'course', you need to rename it. I've highlighted the route name in your config:

'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'
                 ),
             ),
         ),
     )
 ),
0
votes

Problem for me was that I didn't register newly created module in /config/modules.config.php