2011-08-18 2 views

답변

4

사용 strrpos() 문자열에 '/'마지막의 위치를 ​​발견하고 이후 모든 반환 :

$url = 'site.com/some/other/path';  
echo substr($url, strrpos($url, '/') + 1); // Output: 'path' 

을 URL을 얻으려면, 당신은 사용할 수 있습니다

basename($this->getRequest()->getRequestUri()); 

stated by John Cartwright.

$path = $this->_request->getRequestUri(); 
$parts = explode('/', $path); 
$lastPathComponent = end($parts); 

$this->view->lastPathComponent = $lastPathComponent; 

을 또는 여러 컨트롤러 (예를 들어, 레이아웃을) 사용되는 뷰에서이를 사용하려는 경우를 반환하는 뷰 헬퍼를 만들 :

1

어느 컨트롤러에서 뷰 변수에 할당 마지막 경로 구성 요소를 만들고 뷰에서 호출하십시오.

<?=$this->escape($this->lastPathComponent())?> 
1

요청 개체에서 URL을 가져온 다음 basename()을 결과에 적용 할 수 있습니다.

echo basename($this->getRequest()->getRequestUri()); 
관련 문제