CI 静态 D/C/M 路由和 URI 参数
我有一点棘手,我什至不确定 CI 是否被设计为以这种方式工作。
我有一个子域,我们称之为 test.warren.com
test.warren.com 指向 CI index.php,它与访问 warren.com 时加载的主 index.php 是分开的。
test.warren.com 的 index.php 定义了静态路由,根据 CI 注释
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
* specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
* IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
* specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
*
*/
// The directory name, relative to the "controllers" folder. Leave blank
// if your controller is not in a sub-folder within the "controllers" folder
$routing['directory'] = 'subdir';
// The controller class file name. Example: Mycontroller
$routing['controller'] = 'testcontroller';
// The controller function you wish to be called.
$routing['function'] = 'testmethod';
现在这一切都正常了 - 我有我的单一方法网站。没有其他东西可以访问;只有那个方法。如果我访问 test.warren.com - 我会得到 testmethod() 执行的任何内容。
现在,我不能做的部分是传递 URI 参数 EG:test.warren.com/param1/param2/param3 --- 404
据我调试,这不起作用的原因是因为当初始化路由器类时,它会尝试检查“param1”是否是控制器类或目录;这符合标准 CI 配置的预期。然后就出现 404 错误了。
我想我可以通过编辑在index.php底部加载的main core/CodeIgniter.php来解决这个问题;但我非常犹豫,因为这个 CI 安装有多个站点安装。
CI 是 v2.0.3
有谁知道这是否可能?
I have a bit of a tricky one, and I'm not even sure if CI is designed to work this way.
I have a subdomain, lets call it test.warren.com
test.warren.com points to a CI index.php, which is separate from the main index.php that is loaded when accessing warren.com.
The test.warren.com's index.php has static routes defined, as per the CI comments
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
* specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
* IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
* specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
*
*/
// The directory name, relative to the "controllers" folder. Leave blank
// if your controller is not in a sub-folder within the "controllers" folder
$routing['directory'] = 'subdir';
// The controller class file name. Example: Mycontroller
$routing['controller'] = 'testcontroller';
// The controller function you wish to be called.
$routing['function'] = 'testmethod';
Now this all works dandy - I have my one-method website. Nothing else is accessible; only that method. If I go to test.warren.com - I get whatever is executed by testmethod().
Now, the part I can't do - is pass in URI params
EG: test.warren.com/param1/param2/param3 --- 404
As far as I can debug the reason this doesn't work is because when the router class is initialized, it tries to check if 'param1' is a controller class or a directory; which is in-line with what a standard CI configuration would expect. And then 404s out.
I think I can work around it by editing the main core/CodeIgniter.php that is loaded at the bottom of index.php; but I'm very hesitant as this CI installation has multiple site installations.
CI is v2.0.3
Does anyone know if this is possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您以这种方式使用“默认路由”,则需要设置辅助路由来传递参数。
即
这个“应该”工作,为了匹配它,你必须传递三个参数,如果你不传递三个参数,它将恢复为默认控制器或 404 (如果只传递一两个)。
希望有帮助?
If you are using your "default route" in this way, you will need to setup a secondary route to pass the paramaters.
i.e.
This "should" work, as to match it, you would have to pass three parameters and if you don't pass three, it will revert to the default controller or 404 (if only one or two are passed.)
Hope that helps?