Codeigniter, get variable from segment-based URL with querystrings
i've removed the index.php from my url but now i need to get some variable from the url , the CI solution is update the config.php
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;
this work perfectly when i use the index.php in the url , but i need it without index.php
this is my httacess
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,Q开发者_JAVA百科SA
any solution ? , thx
I had the same problem in CI, so I wrote this function to get the query strings from the $_SERVER['REQUEST_URI'] variable and extract them.
function extract_querystrings() {
$uri = $_SERVER['REQUEST_URI'];
$uri = explode('?',$uri);
if (count($uri)>1) {
foreach($uri AS $ur) {
$ur = explode('&',$ur);
foreach($ur AS $u) {
$u = explode('=',$u);
if ($u[0]=='/') continue;
$this->query_strings[$u[0]] = $this->input->xss_clean($u[1]);
}
}
}
//echo '<pre>',print_r($this->query_strings,true),'</pre>';
}
This function is called at my custom main controller's __construct().
You can modify the following line from
$this->query_strings[$u[0]] = $this->input->xss_clean($u[1]);
To
$_GET[$u[0]] = $this->input->xss_clean($u[1]);
And see if it works for you.
Have you looked at Elliot Haughin's Facebook library for CodeIgniter? It might provide some insights into using CI with Facebook.
http://www.haughin.com/code/facebook/
精彩评论