[英]CodeIgniter - Routing urls with GET Variables
我檢查了類似的問題,但那些似乎沒有幫助。
我有一個類似的電子郵件驗證,即在CodeIgniter中路由到正確的函數,數據傳遞給函數進行進一步處理。
示例網址:
http://mysite.dev/verify/?id=emailaddress@gmail.com&hash=562828a975740ac6820e40f7f61b4407
目前的路線:
$route['verify/(:any)'] = 'formcontroller/verification/$1';
功能:
public function verification($slug)
{
parse_str(parse_url($slug, PHP_URL_QUERY), $fileds);
var_dump($fields);
}
問題是,當我嘗試上面列出的網址時,我得到了404。 我收到Message: Undefined variable: fields
當我嘗試像http://amazon.dev/verify/asdasdasd
這樣的Message: Undefined variable: fields
時
有人能指出我正確的方向嗎?
ADD:如果沒有?
在網址中,它的工作原理。 但是對於get查詢url的標准應該是,我想知道如何解決這個問題
據我所知,路由不接收查詢字符串。 所以,你應該從GET數組獲得變量。 為此,在config.php中設置的第一個測試
$config['allow_get_array'] = TRUE;
然后在控制器中:
public function verification($slug)
{
$fields['id'] = $this->input->get('id');
$fields['hash'] = $this->input->get('hash');
var_dump($fields);
}
問題實際上是,查詢在/
后啟動。
實際上網址應該在這個模型中, ?
緊跟目錄名后。
http://mysite.dev/verify/?id=emailaddress@gmail.com&hash=562828a975740ac6820e40f7f61b4407
路線應該是
$route['verify'] = 'formcontroller/verification';
並且應該使用CodeIgniter
get
方法處理變量。
$this->input->get('variablename');
此外,如果配置文件不是唯一允許的任何字符,則url應該只是urlencoded
。
只有URL的路徑段是可路由的,您不需要解析查詢參數......
通過$_GET
超全局(如原始PHP)或通過Input類'get()方法訪問它們。
的?
不是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!!
|
*/
它位於application / config / config.php中
$config['permitted_uri_chars'] = 'a-z 0-9~%.:&_\-';
你可以追加? 到列表
這是一個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.