KohanaPHP 3 Routing Issues

若如初见. 提交于 2019-12-25 08:14:12

问题


I'm having a route for user controller. This controller has about 20 methods so I don't want to set them manually in routes:

Route::set('user', 'user/<action>')
        ->defaults(array(
            'controller' => 'user',
            'action'     => 'index',
        ));

I have also pictures controller (Controller_User_Pictures) with multiple methods that is used to manage users pictures. When I create a route:

Route::set('pictures', 'user/pictures/<action>')
        ->defaults(array(
            'directory'  => 'user',
            'controller' => 'user_pictures',
            'action'     => 'index',
        ));

It's not working.

Even if I create a separate controller (Controller_Pictures) and create route it's not working:

Route::set('pictures', 'user/pictures/<action>')
        ->defaults(array(
            'directory'  => 'user',
            'controller' => 'pictures',
            'action'     => 'index',
        ));

In all cases it returns error: Method action_pictures does not exist which means that router is looking for an action called pictures in user controller which of course is wrong.

The only solution that I'm thinking of, is to define all routes in bootstrap.php file. Do you have better solution?

Edit Second question, do have any idea how to replace underscore with hyphen in any actions (of course in routing)?


回答1:


The order of the routes is important; specific routes should come first.

So your url user/pictures/<action> is triggering the first route. If you put the pictures-route above the general user-route, it should work just fine.

Another side-note: if you specify directory 'user', your controller would be Controller_User_Pictures in classes/controller/user/pictures.php



来源:https://stackoverflow.com/questions/5324047/kohanaphp-3-routing-issues

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