从具有多个控制器的URL中隐藏Codeigniter控制器名称 [英] Hide Codeigniter controller name from URL with multiple controllers

查看:140
本文介绍了从具有多个控制器的URL中隐藏Codeigniter控制器名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的routes.php中使用以下代码来从URL结构中隐藏控制器名称:

I'm using the following code in my routes.php to hide the controller name from the URL structure:

$route['(:any)'] = "auth/$1";

它工作得很好,但我的问题是:当我想访问另一个控制器,将其作为隐藏控制器的函数。

It works great, but my problem is this: When I want to access another controller, it seems to treat it as a function of the hidden controller.

例如。我有

http://mysite.com/controller1/somefunction

它变成:

http://mysite.com/somefunction

如果我想访问:

http://mysite.com/jsonfunction/anotherfunction/


$ b b

如何访问其他控制器,同时保持另一个控制器隐藏?我真的不希望访问者看到 http://mysite.com/maincontroller/ 这只是多余的!

推荐答案

你将不得不更具体地定义你的路由我害怕。
您仍然可以使用:

You are going to have to define your routes more specific I am afraid. You can still use:

$route['(:any)'] = "auth/$1";

但它可能会转到您的路由列表的按钮。

But it will probably go to the button of your list of routes.

如果你想添加其他路由,推翻一个你必须把它们放在顶部。
例如像这样:

if you want other routes to be added that overrule that one you'll have to place them on top. For example like this:

$route['login'] = "auth/login";
$route['varY'] = "controllerX/varY";
$route['varY/(:any)'] = "controllerX/varY/$1";
$route['foobar'] = "controller/method";
$route['(:any)'] = "auth/$1";

有关详细信息和未来参考,请参阅此文档:
http://codeigniter.com/user_guide/general/routing.html

See this document for more info and future reference: http://codeigniter.com/user_guide/general/routing.html

这篇关于从具有多个控制器的URL中隐藏Codeigniter控制器名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆