Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

YII 2 Get Site URL

My Application is deployed on localhost/upload.

I am using following code to generate relative URL.

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

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

Am I missing something?

like image 683
Touqeer Shafi Avatar asked Jan 15 '15 08:01

Touqeer Shafi


1 Answers

You should simply use a route :

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

And if you want an absolute base url :

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

Read more :

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

like image 196
soju Avatar answered Oct 11 '22 20:10

soju