2010-04-29 2 views
0

symfony로 sfDoctrineRoute에서 사용자 세션을 처리하는 방법은 무엇입니까?symfony로 sfDoctrineRoute에서 사용자 세션에 액세스하는 방법?

var_dump(sfContext::getInstance()->getUser());  

반환 내가

Accessing user session from a custom routing class = 나쁜 응답

+1

정확히 달성하려는 것은 무엇입니까? 우리에게 좀 더 배경을 줄 수 있어요? 많은 경우에 sfContext :: getInstance()는 anwser가 아닙니다. :-) – richsage

+0

URL에서 정보를 전달하여 컨트롤러의 동작에서 라우팅 객체를 검색하고 싶지 않습니다. 사용자 지정 라우팅 클래스를 만들고 사용자 세션을 검색 할 수 없습니다. – belaz

답변

0

당신은 컨트롤러에서 sfDoctrineRoute::setQuery() 방법을 사용해야합니다 라우팅에서 현재 사용자 세션에 액세스, 그 sfUser를 사용하여 쿼리를 생성하지 못할

를 NULL 참조 및 예를 들어 포함 된 사용자 자격 증명 :

protected function executeIndex(sfWebRequest $request) 
{ 
    $query = Doctrine::getTable('Foo') 
    ->createQuery('f') 
    ->whereIn('f.access_level', $this->getUser()->getCredentials()) 
    ; 

    $this->getRoute()->setListQuery($query); 

    $this->foo_list = $this->getRoute()->getObjects(); 
} 

희망이 있습니다.

PS : ALWAYS avoid calling sfContext::getInstance()이어야합니다.

관련 문제