Reputation: 11829
Is there a way to access the rewritten $_GET
variables in my onBeginRequest
event handler when using a parameterized route?
My route is defined as:
'<_c:\w+>/<_a:\w+>/<id:\d+>' => '<_c>/<_a>'
And my event handler is:
'onBeginRequest' => function($event) {
/*
site.com/posts/edit/1 - empty (bad)
site.com/posts/edit/?id=1 - not empty(good)
*/
var_dump($_GET);
die;
}
How do I make sure that $_GET['id'] is defined no matter which of the two URLs above is requested?
I am using Yii version 1.1.13.
Upvotes: 2
Views: 430
Reputation: 437336
You do this by having the url manager component parse the current request url:
$app = Yii::app();
$app->getUrlManager()->parseUrl($app->getRequest());
This will populate $_GET
and $_REQUEST
appropriately according to your route. It will also return the active route (controller/action pair), but I am not doing anything with the return value because it looks like you don't need it here.
Upvotes: 2