YII 2 Get Website URL

My application is deployed to localhost / upload.

I use the following code to generate relative URLs.

Url::to('@web/my_controller/action'); // it returns /upload/my_controller/action 

But instead, I need the full URL: http: // localhost / upload / my_controller / action .

Did I miss something?

+6
source share
2 answers

You should just use the route:

 Url::to(['my_controller/action']); 

And if you want an absolute base url:

 Url::to(['my_controller/action'], true); 

More details:

http://www.yiiframework.com/doc-2.0/yii-helpers-baseurl.html#to()-detail

http://www.yiiframework.com/doc-2.0/guide-runtime-routing.html#creating-urls

+6
source

Follow urlmanager and query in Yiiframework 2.0 with example


  • Yii :: $ app-> basePath **** → → **** D: \ wamp \ www \ yiiframework2.0 \ project \ backend

  • Yii :: $ app-> homeUrl; **** → → **** / yiiframework2.0 / project / backend / web / index.php

  • Yii :: $ app-> getUrlManager () → createUrl ('user) **** → → **** / yiiframework2.0 / project / backend / web / index.php? R = user

  • Yii :: $ app-> urlManager-> createUrl (['site / page,' id => 'about]) **** → → ****
    / yiiframework 2.0 / project / backend / web / index.php? r = site% 2Fpage & id = about

  • Yii :: $ app-> urlManager-> createUrl (['site / view,' id => 105]) **** → → **** / yiiframework2.0 / project / backend / web / index.php? r = site% 2Fview & id = 105



  • Yii :: $ app-> request-> baseUrl **** → → **** / yiiframework2.0 / project / backend / web


  • Yii :: $ app-> request-> url **** → → ****
    / yiiframework 2.0 / project / backend / web / index.php
+2
source

Source: https://habr.com/ru/post/981036/


All Articles