Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 751 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get current URL/URI without some of $_GET variables

#11
echo Yii::$app->request->url;
Reply

#12
In Yii2 you can do:

use yii\helpers\Url;
$withoutLg = Url::current(['lg'=>null], true);

More info:

[To see links please register here]



Reply

#13
Yii2

Url::current([], true);
or

Url::current();
Reply

#14
## Yii 1
Yii::app()->request->url

## For Yii2:
Yii::$app->request->url
Reply

#15
For Yii2:
This should be safer `Yii::$app->request->absoluteUrl` rather than `Yii::$app->request->url`
Reply

#16
Yii 1
-----

Most of the other answers are wrong. The poster is asking for the url WITHOUT (some) $_GET-parameters.

Here is a complete breakdown (creating url for the currently active controller, modules or not):

// without $_GET-parameters
Yii::app()->controller->createUrl(Yii::app()->controller->action->id);

// with $_GET-parameters, HAVING ONLY supplied keys
Yii::app()->controller->createUrl(Yii::app()->controller->action->id,
array_intersect_key($_GET, array_flip(['id']))); // include 'id'

// with all $_GET-parameters, EXCEPT supplied keys
Yii::app()->controller->createUrl(Yii::app()->controller->action->id,
array_diff_key($_GET, array_flip(['lg']))); // exclude 'lg'

// with ALL $_GET-parameters (as mensioned in other answers)
Yii::app()->controller->createUrl(Yii::app()->controller->action->id, $_GET);
Yii::app()->request->url;

When you don't have the same active controller, you have to specify the full path like this:

Yii::app()->createUrl('/controller/action');
Yii::app()->createUrl('/module/controller/action');

Check out the Yii guide for building url's in general:

[To see links please register here]



Reply

#17
**For Yii1**

I find it a clean way to first get the current route from the CUrlManager, and then use that route again to build the new url. This way you don't 'see' the baseUrl of the app, see the examples below.

Example with a controller/action:
```
GET /app/customer/index/?random=param
$route = Yii::app()->urlManager->parseUrl(Yii::app()->request);
var_dump($route); // string 'customer/index' (length=14)
$new = Yii::app()->urlManager->createUrl($route, array('new' => 'param'));
var_dump($new); // string '/app/customer/index?new=param' (length=29)
```

Example with a module/controller/action:
```
GET /app/order/product/admin/?random=param
$route = Yii::app()->urlManager->parseUrl(Yii::app()->request);
var_dump($route); // string 'order/product/admin' (length=19)
$new = Yii::app()->urlManager->createUrl($route, array('new' => 'param'));
var_dump($new); string '/app/order/product/admin?new=param' (length=34)
```

This works only if your urls are covered perfectly by the rules of CUrlManager :)
Reply

#18
For Yii2
========

I was rather surprised that the correct answer for Yii2 was in none of the responses.

The answer I use is:

Url::to(['']),

You can also use:

Url::to()

...but I think the first version makes it more obvious that your intention is to generate a url with the curent request route. (i.e. "/index.php?admin%2Findex" if you happened to be running from the actionIndex() in the AdminController.

You can get an absolute route with the schema and domain by passing true as a second parameter, so:

Url::to([''], true)

...would return something like "https://your.site.domain/index.php?admin%2Findex" instead.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through