Symfony \ Component \ HttpFoundation \ Request的getBaseUrl和getBasePath之间有什么区别?我想知道何时使用其中一个。
答案 0 :(得分:1)
getBaseUrl还包含脚本文件名。
phpDoc评论为您提供了进一步的解释:
getBasePath:
/**
* Returns the root path from which this request is executed.
*
* Suppose that an index.php file instantiates this request object:
*
* * http://localhost/index.php returns an empty string
* * http://localhost/index.php/page returns an empty string
* * http://localhost/web/index.php returns '/web'
* * http://localhost/we%20b/index.php returns '/we%20b'
...
getBaseUrl:
/**
* Returns the root URL from which this request is executed.
*
* The base URL never ends with a /.
*
* This is similar to getBasePath(), except that it also includes the
* script filename (e.g. index.php) if one exists.
...
答案 1 :(得分:-2)
getBasePath()
会将文件夹返回给你php脚本:
/ CoreBundle /控制器/
getBaseUrl()
将返回文件夹和脚本:
/CoreBundle/Controller/ClientController.php