Here’s what’s going on:
index.php?url=/controller/action/
then its $_GET['url']
is filled with this address url=/controller/action/
!!!
To recover effectively use $_SERVER['REQUEST_URI']
that the same will bring: /controller/action/?q=nome
.
Ready now just work with routines that value:
1) Simple example:
$url = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI']: '';
if ($url != ''){
$urls = explode('/', $url);
$param = str_replace('?','', end($urls));
$param = explode('&', $param);
$params = array();
foreach($param as $pa){
$vp = explode('=', $pa);
$params[$vp[0]] = sizeof($vp)==2?$vp[1]:NULL;
}
//só para imprimir valor na tela!!! var_dump
var_dump($params);
}
Upshot:
2) Example with parse_url
var_dump(parse_url($_SERVER['REQUEST_URI']));
Upshot:
array(2) { ["path"]=> string(19) "/controller/action/" ["query"]=> string(6) "q=nome" }
Reference
You could put an example of PHP code where you try to get the values via GET?
– Guilherme
I put something like $test = $_GET['query'] in my controller and then pass it to my view.
– Thiago
so, but if you’re using
?q=nome
url, try to use$_GET['q']
in the code...– Guilherme
It was just an example, but it doesn’t work
– Thiago
Url = $1 why to use q in the requested link parameter ?
– Edilson