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

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

[To see links please register here]


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
);
Reply

#2
I don't know about doing it in Yii, but you could just do this, and it should work anywhere (largely lifted from my answer [here](

[To see links please register here]

)):

// Get HTTP/HTTPS (the possible values for this vary from server to server)
$myUrl = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] && !in_array(strtolower($_SERVER['HTTPS']),array('off','no'))) ? 'https' : 'http';
// Get domain portion
$myUrl .= '://'.$_SERVER['HTTP_HOST'];
// Get path to script
$myUrl .= $_SERVER['REQUEST_URI'];
// Add path info, if any
if (!empty($_SERVER['PATH_INFO'])) $myUrl .= $_SERVER['PATH_INFO'];

$get = $_GET; // Create a copy of $_GET
unset($get['lg']); // Unset whatever you don't want
if (count($get)) { // Only add a query string if there's anything left
$myUrl .= '?'.http_build_query($get);
}

echo $myUrl;

Alternatively, you could pass the result of one of the Yii methods into [`parse_url()`](

[To see links please register here]

), and manipulate the result to re-build what you want.
Reply

#3
Something like this should work, if run in the controller:

$controller = $this;
$path = '/path/to/app/'
. $controller->module->getId() // only necessary if you're using modules
. '/' . $controller->getId()
. '/' . $controller->getAction()->getId()
. '/';

This assumes that you are using 'friendly' URLs in your app config.
Reply

#4


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

This will output something in the following format:

[To see links please register here]


Reply

#5
Try to use this variant:

<?php echo Yii::app()->createAbsoluteUrl('your_yii_application/?lg=pl', array('id'=>$model->id));?>


It is the easiest way, I guess.
Reply

#6
So, you may use

Yii::app()->getBaseUrl(true)


to get an Absolute webroot url, and strip the http[s]://
Reply

#7
To get the absolute current request url (exactly as seen in the address bar, with GET params and http://) I found that the following works well:

Yii::app()->request->hostInfo . Yii::app()->request->url
Reply

#8
$validar= Yii::app()->request->getParam('id');
Reply

#9
You are definitely searching for this

Yii::app()->request->pathInfo
Reply

#10
Most of the answers are wrong.

The Question is to get url without some query param .

Here is the function that works. It does more things actually. You can remove the param that you don't want and you can add or modify an existing one.

/**
* Function merges the query string values with the given array and returns the new URL
* @param string $route
* @param array $mergeQueryVars
* @param array $removeQueryVars
* @return string
*/
public static function getUpdatedUrl($route = '', $mergeQueryVars = [], $removeQueryVars = [])
{
$currentParams = $request = Yii::$app->request->getQueryParams();

foreach($mergeQueryVars as $key=> $value)
{
$currentParams[$key] = $value;
}

foreach($removeQueryVars as $queryVar)
{
unset($currentParams[$queryVar]);
}

$currentParams[0] = $route == '' ? Yii::$app->controller->getRoute() : $route;

return Yii::$app->urlManager->createUrl($currentParams);

}

usage:

ClassName:: getUpdatedUrl('',[],['remove_this1','remove_this2'])

This will remove query params 'remove_this1' and 'remove_this2' from URL and return you the new URL
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

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