1

Been trying to learn codeigniter, 1 problem I had though is that if I had a function say

top_10()

It would mean that my urls will be something like

..../top_10/

Which is fine but I prefer - more than _ for urls. I tried changing my function names to top-10(), but it results in a syntax error it seems (even if it doesn't it results in a ugly function name), Is there a way to let codeigniter auto converts all the _ in my controller functions to - when it comes to the urls?

.../top_10/ -> .../top-10/ for all other similar controller functions.

4

2 回答 2

0

您可以使用 URI 路由规则
,例如:
$route['controller/top-10'] = "controller/top_10";

在 routes.php 文件里面添加这一行application/config/routes.php

controller/top-10将是您的 url 的一部分,它将被路由到右侧提供的所需功能。另外,如果您不使用 mod_rewrite 重写您的 url,那么您的 URL 将出现类似 http://localhost/index.php/controller/top-10

于 2011-05-22T02:41:06.410 回答
0

如果在您的application/config/routes.php文件夹中没有用于翻译 uri 破折号的行,则添加以下行:$route['translate_uri_dashes'] = TRUE;

如果$route['translate_uri_dashes']已经存在,只需将其值设置为 true。

于 2018-05-25T13:02:38.053 回答