Retrieve information about the current route

symfony PHP5 framework

Retrieve information about the current route
If you need to retrieve information about the current route, for instance to prepare a future 'back to page xxx' link, you should use the methods of the sfRouting object. For instance, if your routing.yml defines:

  url:   /call_my_rule
  param: { module: mymodule, action: myaction }

Use the following calls in the action:

// if you require an URL like
$uri = sfRouting::getInstance()->getCurrentInternalUri();
// will return 'mymodule/myaction?param1=xxx&param2=yyy'
$uri = sfRouting::getInstance()->getCurrentInternalUri(true);
// will return '@myrule?param1=xxx&param2=yyy'
$route = sfRouting::getInstance()->getCurrentRouteName();
// will return 'myrule'

The URIs returned by the ->getCurrentInternalUri() method can be used in a call to a link_to() helper.
In addition, you might want to get the first or the last action called in a template. The following variables are automatically updated at each request and are available to templates:


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください