【问题标题】:How to get the request URL relative to the application root?如何获取相对于应用程序根的请求 URL?
【发布时间】:2013-04-30 21:07:18
【问题描述】:

如果我这样做:

print Yii::app()->request->url;

我明白了:

/www/site/contact

在我的本地机器上。但在我的网站上,我得到:

/site/contact

如何获取 index.php 所在的路径,以便在本地和我的服务器上都得到:

/site/contact

【问题讨论】:

    标签: yii


    【解决方案1】:

    从请求 url 中去掉 baseUrl 可以通过 Yii::app()->baseUrl 获得。

    一种方法是:

    $app = Yii::app();
    print substr($app->request->url, strlen($app->baseUrl));
    

    【讨论】:

      猜你喜欢
      • 2015-03-29
      • 2014-09-30
      • 1970-01-01
      • 2014-11-17
      • 2017-01-09
      • 2011-07-15
      • 1970-01-01
      • 1970-01-01
      • 2011-01-19
      相关资源
      最近更新 更多