Kohana 3: Routing with subdirectories error, controller does not exist

老子叫甜甜 提交于 2019-12-11 04:35:49

问题


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

回答1:


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.




回答2:


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',
    ));


来源:https://stackoverflow.com/questions/3884255/kohana-3-routing-with-subdirectories-error-controller-does-not-exist

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!