views:

48

answers:

2

So I'm trying to build a route with sub directories and following the Kerkness wiki guide but keep getting errors. If someone could point out what I'm doing wrong I would greatly appreciate it.

http://kerkness.ca/wiki/doku.php?id=routing:building_routes_with_subdirectories

The code:

Route::set('default', '(<directory>(/<controller>(/<action>(/<id>))))', array('directory' => '.+?'))
    ->defaults(array(
        'directory'  => 'admin',
        'controller' => 'main',
        'action'     => 'index',
    ));

The url:

/admin/weather/feedback

The file:

/application/classes/controller/admin/weather/feedback.php
class Controller_Admin_Weather extends Controller_Admin_Base {

The error:

 ReflectionException [ -1 ]: Class controller_admin_weather does not exist
A: 

Weather needs to be the controller not feedback. Make a weather.php in the admin folder and put the controller as Controller_Admin_Weather and then the action action_feedback.

mikelbring
A: 

As @mikelbring said, your controller class is named wrongly. A class in that file should be called Controller_Admin_Weather_Feedback

Do you really need so many optional segments in your route? Also; if there are no variable elements to the urls you can just stick with defaults like this:

Route::set('my_route_name', 'admin/weather/feedback')
    ->defaults(array(
        'directory'  => 'admin/weather',
        'controller' => 'feedback',
        'action'     => 'index',
    ));

If your class was in /application/classes/controller/admin/weather.php and had an action_feedback(...) method, you could use the following route

Route::set('my_route_name', 'admin/weather/feedback')
    ->defaults(array(
        'directory'  => 'admin',
        'controller' => 'weather',
        'action'     => 'feedback',
    ));
Lethargy