6
5

More than 5 years have passed since last update.

Symfony2でUrl取得

Last updated at Posted at 2014-06-07

requestオブジェクトから現在のUrl等取得できます。
基本getUriForPathでよさそう。

echo 'getBasePath : '.$request->getBasePath() . '<br>';
echo 'getBaseUrl : '.$request->getBaseUrl() . '<br>';
echo 'getRequestUri : '.$request->getRequestUri() . '<br>';
echo 'getUri : '.$request->getUri() . '<br>';
echo 'getUriForPath : '.$request->getUriForPath('/') . '<br>';


getBasePath : /snap/web
getBaseUrl : /snap/web/app_dev.php
getRequestUri : /snap/web/app_dev.php/App/model/99
getUri : http://localhost/snap/web/app_dev.php/App/model/99
getUriForPath : http://localhost/snap/web/app_dev.php/

参考:http://api.symfony.com/2.0/Symfony/Component/HttpFoundation/Request.html#method_getBasePath

6
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
5