Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generate url in module and outside of module in Yii2

I have a module with the name of admin. when i generate link with Url::to(['admin/assignment']) outside of module it's work and create this link:

http://localhost:8080/test/backend/web/admin/assignment.html

but when this url generated in running current module it's create this linke and doesn't work

http://localhost:8080/test/backend/web/admin/admin/assignment.html

how can i create a rule in route (UrlManager) for control problem like this!

like image 926
Araz Jafaripur Avatar asked Nov 03 '14 19:11

Araz Jafaripur


People also ask

How to create URL in yii2?

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

How to get URL in yii2?

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() .

How to get value from URL in yii2?

Yii::app()->request->getUrl(); Yii::app()->request->getParams('id'); $_GET['id'];


1 Answers

Try Url::to(['/admin/assignment']) (with the leading /): routes without the leading / are interpreted as relative to the current module.

like image 183
david Avatar answered Sep 28 '22 07:09

david