Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current URL/URI without some of $_GET variables

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  ); 
like image 900
Sebastian Avatar asked Dec 07 '11 09:12

Sebastian


People also ask

How to get current URL in php without parameters?

The simplest solution would be: echo parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH);

How to get current URL parameters in php?

Answer: Use the PHP $_SERVER Superglobal Variable You can use the $_SERVER built-in variable to get the current page URL in PHP. The $_SERVER is a superglobal variable, which means it is always available in all scopes.

How can I get current URL in Yii?

Yii::app()->request->getUrl() method is used to get current url in Yii framework.


2 Answers

Yii 1

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

For Yii2:

Yii::$app->request->url 
like image 142
Felipe Avatar answered Sep 22 '22 23:09

Felipe


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

This will output something in the following format:

http://www.yoursite.com/your_yii_application/ 
like image 31
Bhargav Avatar answered Sep 18 '22 23:09

Bhargav