【问题标题】:Codeigniter Routes.php within folder文件夹中的 Codeigniter Routes.php
【发布时间】:2014-01-17 18:44:21
【问题描述】:

我在 Server2008 上使用最新版本的 CodeIgniter 和 IIS7.5

我的所有 CI 文件都放在 mywebsite.com/survey 文件夹中

nps = Controller
survey = Function
client_id = variable base64 encoded client number

我有一个在您访问时运行的脚本: http://mywebsite.com/survey/nps/survey/client_id/MjgzOTcyMW

但我希望它在您访问时运行: http://mywebsite.com/survey/MjgzOTcyMW

如何设置我的 routes.php?

我目前有:

$route['/:any'] = 'nps/survey/client_id/';

【问题讨论】:

  • 试试这个$route['(:any)'] = 'nps/survey/$1';

标签: codeigniter url-rewriting routes


【解决方案1】:

你必须确保你不会在这里混淆你的路线:

仅使用 $route['/:any'] 是错误的(即使您的 (:any) 正确。 要正确定义路线),请记住左侧是模式路线,右侧(在=之后)是翻译后的controller/method/parameter格式。

所以定义路线(在所有其他路线之后),因为它们将从最具体到最不具体(类似于 ALLOW/DENY 规则等)排序:

$route['survey/(:any)'] = 'nps/survey/client_id/$1';

【讨论】:

  • 感谢您解释我哪里出错了。我对路线还是很陌生,这绝对帮助了很多人。
【解决方案2】:

试试

$route['(:any)'] = 'nps/survey/client_id/$1';

$route['survey/(:any)'] = 'nps/survey/client_id/$1';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-25
    • 2018-01-09
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多