【问题标题】:Kohana 3: Routing with subdirectories error, controller does not existKohana 3:带有子目录的路由错误,控制器不存在
【发布时间】:2011-04-22 12:08:28
【问题描述】:

所以我正在尝试使用子目录构建一条路线并遵循 Kerkness wiki 指南,但不断出现错误。如果有人能指出我做错了什么,我将不胜感激。

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

代码:

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

网址:

/admin/weather/feedback

文件:

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

错误:

 ReflectionException [ -1 ]: Class controller_admin_weather does not exist

【问题讨论】:

    标签: php routing kohana


    【解决方案1】:

    天气需要是控制器而不是反馈。在 admin 文件夹中创建一个 weather.php 并将控制器作为 Controller_Admin_Weather 和 action action_feedback。

    【讨论】:

      【解决方案2】:

      正如@mikelbring 所说,您的控制器类命名错误。该文件中的类应称为Controller_Admin_Weather_Feedback

      您的路线中真的需要这么多可选路段吗? 还;如果 url 没有可变元素,你可以坚持使用这样的默认值:

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

      如果你的班级在/application/classes/controller/admin/weather.php 并且有一个action_feedback(...) 方法,你可以使用以下路线

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-21
        • 2012-11-04
        • 1970-01-01
        相关资源
        最近更新 更多