Get current URL/URI without some of $_GET variables

Sebastian picture Sebastian · Dec 7, 2011 · Viewed 124.3k times · Source

How, in Yii, to get the current page's URL. For example:

http://www.yoursite.com/your_yii_application/?lg=pl&id=15

but excluding the $GET_['lg'] (without parsing the string manually)?

I mean, I'm looking for something similar to the Yii::app()->requestUrl / Chtml::link() methods, for returning URLs minus some of the $_GET variables.

Edit: Current solution:

unset $_GET['lg'];

echo Yii::app()->createUrl(
  Yii::app()->controller->getId().'/'.Yii::app()->controller->getAction()->getId() , 
  $_GET 
);

Answer

Felipe picture Felipe · Oct 29, 2012

Yii 1

Yii::app()->request->url

For Yii2:

Yii::$app->request->url