Symfony HttpFoundation Request getBaseUrl () vs getBasePath ()

What is the difference between getBaseUrl and getBasePath Symfony \ Component \ HttpFoundation \ Request? I would like to know when to use one over the other.

+3


source to share


2 answers


getBaseUrl also contains the script file name.

PhpDoc comments give you an additional explanation:

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


source


getBasePath()

will return you folders for PHP script: / CoreBundle / Controller /



getBaseUrl()

will give you back folders and script: /CoreBundle/Controller/ClientController.php

-1


source







All Articles