KohanaPHP 3路由问题

编程入门 行业动态 更新时间:2024-10-27 12:42:09
本文介绍了KohanaPHP 3路由问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为用户控制器路由.该控制器有大约20种方法,所以我不想在路由中手动设置它们:

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

我还有图片控制器(Controller_User_Pictures),它具有用于管理用户图片的多种方法.当我创建路线时:

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

它不起作用.

即使我创建了一个单独的控制器(Controller_Pictures)并创建了路由,它也不起作用:

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

在所有情况下,它都会返回错误:Method action_pictures does not exist,这意味着路由器正在用户控制器中寻找称为图片的操作,这当然是错误的.

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.

我唯一想到的解决方案是在bootstrap.php文件中定义所有路由.您有更好的解决方案吗?

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)?

推荐答案

路由的顺序很重要;具体路线应该优先.

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

因此您的网址user/pictures/<action>正在触发第一条路由.如果将图片路线放置在常规用户路线上方,则应该可以正常工作.

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.

另一注:如果您指定目录用户",则您的控制器将在classes/controller/user/pictures.php中的Controller_User_Pictures

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

更多推荐

KohanaPHP 3路由问题

本文发布于:2023-11-12 13:48:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581672.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   KohanaPHP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!