[英]CodeIgniter - Routing urls with GET Variables
I checked the similar questions out there, but those doesnt seem to help. 我检查了类似的问题,但那些似乎没有帮助。
I have an email verification like, that is to be routed in CodeIgniter to the right function with data passed to the function for further processing. 我有一个类似的电子邮件验证,即在CodeIgniter中路由到正确的函数,数据传递给函数进行进一步处理。
Sample URL : 示例网址:
http://mysite.dev/verify/?id=emailaddress@gmail.com&hash=562828a975740ac6820e40f7f61b4407
Current Route : 目前的路线:
$route['verify/(:any)'] = 'formcontroller/verification/$1';
Function : 功能:
public function verification($slug)
{
parse_str(parse_url($slug, PHP_URL_QUERY), $fileds);
var_dump($fields);
}
The problem is, I get a 404 when I try the url listed above. 问题是,当我尝试上面列出的网址时,我得到了404。 I get
Message: Undefined variable: fields
when I try something like http://amazon.dev/verify/asdasdasd
我收到
Message: Undefined variable: fields
当我尝试像http://amazon.dev/verify/asdasdasd
这样的Message: Undefined variable: fields
时
Can someone point me in the right direction? 有人能指出我正确的方向吗?
ADD : If there is no ?
ADD:如果没有
?
in the url, it works. 在网址中,它的工作原理。 But for the standard of a get query url should be, I would like like to know how to solve this
但是对于get查询url的标准应该是,我想知道如何解决这个问题
Route doesn't receive query string as i understand. 据我所知,路由不接收查询字符串。 So, you should get variable from GET array.
所以,你应该从GET数组获得变量。 For this, 1st test that in config.php set
为此,在config.php中设置的第一个测试
$config['allow_get_array'] = TRUE;
then in controller: 然后在控制器中:
public function verification($slug)
{
$fields['id'] = $this->input->get('id');
$fields['hash'] = $this->input->get('hash');
var_dump($fields);
}
The problem actually was, the query started after a /
. 问题实际上是,查询在
/
后启动。
Actually the url should be in this model, ?
实际上网址应该在这个模型中,
?
immediately after the directory name. 紧跟目录名后。
http://mysite.dev/verify/?id=emailaddress@gmail.com&hash=562828a975740ac6820e40f7f61b4407
Route should be 路线应该是
$route['verify'] = 'formcontroller/verification';
And the variables should be handled using get
method of CodeIgniter
. 并且应该使用
CodeIgniter
get
方法处理变量。
$this->input->get('variablename');
Also, the url should be urlencoded
just incase if there are any characters which are not exclusively allowed by the config file. 此外,如果配置文件不是唯一允许的任何字符,则url应该只是
urlencoded
。
Only the path segment of the URL is routable, and you don't need to parse the query parameters ... 只有URL的路径段是可路由的,您不需要解析查询参数......
Access them via the $_GET
superglobal (like in raw PHP) or via the Input class' get() method . 通过
$_GET
超全局(如原始PHP)或通过Input类'get()方法访问它们。
the ?
的
?
is not a permitted character in the URI segment in 不是URI段中的允许字符
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify with a regular expression which characters are permitted
| within your URLs. When someone tries to submit a URL with disallowed
| characters they will get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
which is located in application/config/config.php 它位于application / config / config.php中
$config['permitted_uri_chars'] = 'a-z 0-9~%.:&_\-';
you can append the ? 你可以追加? to the list
到列表
here is a list of url encoded characters http://www.degraeve.com/reference/urlencoding.php 这是一个url编码字符列表http://www.degraeve.com/reference/urlencoding.php
config.php文件
$config['permitted_uri_chars'] = 'az 0-9~%.:_\\-=';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.