0

How can i get this base url

http://localhost/Symfony/web/app_dev.php/

OR

http://localhost/Symfony/web/app.php/

or

http://localhost/Symfony/web/

(base url)

in symfony2 config file? can't find at symfony website.

Lukas Lukac
  • 7,766
  • 10
  • 65
  • 75
  • Do you mean about url to put in your web browser to achieve project site? Check configuration of virtualHost. – NHG Mar 20 '13 at 14:59

2 Answers2

0
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';

$hostName = $request->server->get('HTTP_HOST');
$baseDirectory = "";
if(!empty($this->container->get('router')->getContext()->getBaseUrl())){
    $baseDirectory = str_replace('app_dev.php', '', $this->container->get('router')->getContext()->getBaseUrl());
}
$rootUrl = $protocol.$hostName.$baseDirectory; 
Paul Roub
  • 36,322
  • 27
  • 84
  • 93
Ashok
  • 1
  • 2
-1

Hmm... check this:

$base = $this->getRequest()->getSchemeAndHttpHost();

or in oldest version (I don't remember when was the change):

$request = $this->getRequest();
$scheme = $request->getScheme();
$host = $request->getHttpHost();

$base = sprintf('%s://%s', $scheme, $host);
mkjasinski
  • 3,115
  • 2
  • 22
  • 21
  • in symfony2 config file? in symfony2 config file? in symfony2 config file? – Lukas Lukac Mar 20 '13 at 14:22
  • set manually in in `parameters.yml` and than use this in `config.yml` by name: `%your_name%`, in controller use my example. BTW: why in config? what for? – mkjasinski Mar 20 '13 at 15:06
  • for JS bundle i need to set url request_context_base_url: "http://localhost/name/web/app_dev.php" – Lukas Lukac Mar 20 '13 at 15:29
  • FOSJsRequestBundle? maybe: `request_context_base_url: ~` and `routes_to_expose` in `[]`. – mkjasinski Mar 20 '13 at 15:41
  • i have everything ready just need this config url parameter... but FOSJS is giving me url like this http://localhost/messages/ and i need localhost/name/web/messages ... and i want it dynamicly not setted by me in parameters or somewhere else – Lukas Lukac Mar 20 '13 at 15:43
  • @Trki server (f.e. apache) must be configured ( f.e. vhost ) on `web` directory and than `localhost/messages` will be correctly. – mkjasinski Mar 20 '13 at 15:51
  • hm... i tried few times configure it but it was never working. Do you have some great tutorial or code in .txt in shortcut? :P – Lukas Lukac Mar 20 '13 at 15:58
  • ` ServerName symfony.localhost DocumentRoot /[path_to_symfony]/web DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all ` – mkjasinski Mar 20 '13 at 16:02
  • hm... and add it to...? :) – Lukas Lukac Mar 20 '13 at 16:13
  • 1
    apache configuration, this is content of virtual host configuration file, look: [apache configuration for symfony](http://stackoverflow.com/questions/8962054/symfony-2-on-virtual-hosts). – mkjasinski Mar 20 '13 at 17:26