使用CodeIgniter通过查询字符串进行自定义URI路由? [英] Custom URI routing by query string with CodeIgniter?
问题描述
我正在寻找使用CodeIgniter框架的自定义路线。我正在尝试使URL像这样:
I am looking to make a custom route using the CodeIgniter framework. I am trying to make the URL like so:
http://localhost/accounts/Auth.dll?signin
到目前为止,我已经尝试将以下内容添加到我的routes.php配置文件中:
So far I have tried adding the following to my routes.php config file:
$route['accounts/Auth.dll?signin'] = "accounts/signin";
但是您可能会猜到,它不起作用。我也尝试过转义这样的字符:
but as you would guess, it doesn't work. I have also tried escaping the characters like this:
$route['accounts/Auth\.dll\?signin'] = "accounts/signin";
,但这都不起作用。我还尝试过使用前导斜线和尾部斜线..也不起作用。有人偶然知道什么可以解决我的问题吗?
and that doesn't work either. I've also tried including the leading and trailing slashes .. that didn't work either. Anyone know by chance what could solve my issue?
推荐答案
我强烈建议使用SEF路由。
I highly recommend to use a SEF routing.
但是如果出于某种原因您不愿意,可以检查 Accounts
控制器内的查询字符串,然后调用正确的方法,如下所示:
But if for any reason you're not eager to, you could check the query string inside the Accounts
Controller, and then invoke the proper method, as follows:
路由器:
$route['accounts/Auth.dll'] = "accounts";
控制器:
class Accounts extends CI_Controller
{
public function __construct()
{
# Call the CI_Controller constructor
parent::__construct();
# Fetch the query string
if ($method = $this->input->server('QUERY_STRING', TRUE)) {
# Check whether the method exists
if (method_exists($this, $method)) {
# Invoke the method
call_user_func(array($this, $method));
}
}
}
protected function signin()
{
# Your logic here
}
}
这使您可以通过查询字符串自动调用方法。
This allows you to invoke the methods by query string automatically.
这篇关于使用CodeIgniter通过查询字符串进行自定义URI路由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!