I am using Yii.
if my url is http://localhost/evengee/event/page/id/2/sfn+master/?tab=3
My real url (file path) is only http://localhost/evengee
How would I obtain, preferably in the view:
http://localhost/evengee/event/page/id/2/sfn+master/?tab=3
http://localhost/evengee/event/page/id/2/sfn+master/
I know I can split/explode str_replace by the ? and use $_SERVER. Would prefer to use Yii native methods.
To get the base URL of the current request use the following: $relativeBaseUrl = Url::base(); $absoluteBaseUrl = Url::base(true); $httpsAbsoluteBaseUrl = Url::base('https'); The only parameter of the method works exactly the same as for Url::home() .
Yii::app()->request->getUrl(); Yii::app()->request->getParams('id'); $_GET['id'];
For example, you can use the following code to create a URL for the post/view action: use yii\helpers\Url; // Url::to() calls UrlManager::createUrl() to create a URL $url = Url::to(['post/view', 'id' => 100]);
For:
full URL (http://localhost/even/page/id/2/?t=3
) use
Yii::app()->request->getUrl()
,
URL without parameters (http://localhost/even/page/id/2/
use
Yii::app()->request->getPathInfo()
.
Second one will give you the URL without schema, server and query string. This seems good enough.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With