2011-05-23 118 views

回答

23

getCurrentInternalUri是,就像他的名字知道的,內部 URL,在內部路由功能,如的link_to使用。

現在的問題是關於當前URI,即使前面的答案被標記爲接受,這裏是在symfony 1.4中獲取當前URI的方法。

$context->getRequest()->getUri(); 

在動作:

public function executeDelete(sfWebRequest $request) 
{ 
    $uri = $request->getUri(); 
} 
+1

工作,我覺得應該是$ sf_context-> Request()方法 - > getUri( ); 感謝您的回答! – GermanK 2014-03-26 16:55:15

11

像這樣:

sfContext::getInstance()->getRouting()->getCurrentInternalUri(); 

這一條可能是使用過:

sfContext::getInstance()->getRouting()->getCurrentRouteName(); 

http://www.symfony-project.org/gentle-introduction/1_4/en/09-Links-and-the-Routing-System#chapter_09_dealing_with_routes_in_actions

UPDATE:

請參考下面達明的答案和im3r3k的評論爲什麼看起來s是一個更好的方法,因爲它不依賴於上下文。

+4

在動作'$請求 - > getUri();'我 – im3r3k 2013-06-22 04:19:39