YII 2 获取站点 URL
YII 2 Get Site URL
我的应用程序部署在 localhost/upload。
我正在使用以下代码生成相对 URL。
Url::to('@web/my_controller/action'); // it returns /upload/my_controller/action
但是,我需要这样的完整 URL:http://localhost/upload/my_controller/action.
我是不是漏掉了什么?
你应该简单地使用一条路线:
Url::to(['my_controller/action']);
如果你想要一个绝对基础 url :
Url::to(['my_controller/action'], true);
阅读更多:
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
在 Yiiframework 2.0 中跟随 urlManager 并请求示例
- 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=用户
- Yii::$app->urlManager->createUrl(['site/page', 'id' => 'about']) ****>>>>* ***
/yiiframework2.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->urlManager->createAbsoluteUrl(”) ****>>>>****
http://127.0.0.1/yiiframework2.0/project/backend/web/index.php?r=
- Yii::$app->urlManager->createAbsoluteUrl('site/view/index') ****>>>>**** http://127.0.0.1/yiiframework2.0/project/backend/web/index.php?r=site%2Fview%2Findex
- Yii::$app->request->baseUrl ****>>>>**** /yiiframework2.0/project/backend/web
- Yii::$app->request->absoluteUrl ****>>>>****
http://127.0.0.1/yiiframework2.0/project/backend/web/index.php
- Yii::$app->请求->url ****>>>>****
/yiiframework2.0/project/backend/web/index.php
我的应用程序部署在 localhost/upload。
我正在使用以下代码生成相对 URL。
Url::to('@web/my_controller/action'); // it returns /upload/my_controller/action
但是,我需要这样的完整 URL:http://localhost/upload/my_controller/action.
我是不是漏掉了什么?
你应该简单地使用一条路线:
Url::to(['my_controller/action']);
如果你想要一个绝对基础 url :
Url::to(['my_controller/action'], true);
阅读更多:
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
在 Yiiframework 2.0 中跟随 urlManager 并请求示例
- 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=用户
- Yii::$app->urlManager->createUrl(['site/page', 'id' => 'about']) ****>>>>* ***
/yiiframework2.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->urlManager->createAbsoluteUrl(”) ****>>>>****
http://127.0.0.1/yiiframework2.0/project/backend/web/index.php?r=
- Yii::$app->urlManager->createAbsoluteUrl('site/view/index') ****>>>>**** http://127.0.0.1/yiiframework2.0/project/backend/web/index.php?r=site%2Fview%2Findex
- Yii::$app->request->baseUrl ****>>>>**** /yiiframework2.0/project/backend/web
- Yii::$app->request->absoluteUrl ****>>>>****
http://127.0.0.1/yiiframework2.0/project/backend/web/index.php
- Yii::$app->请求->url ****>>>>****
/yiiframework2.0/project/backend/web/index.php