views:

92

answers:

1

how to acess user session in sfDoctrineRoute with symfony ?

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

returns NULL

i cant access current user session in routing

http://stackoverflow.com/questions/2455817/symfony-accessing-user-session-from-a-custom-routing-class = bad response

A: 

You should use the sfDoctrineRoute::setQuery() method from your controller, and generate a query using its sfUser reference and, for example, the user credentials it contains:

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();
}

Hope it helps.

PS: you should ALWAYS avoid calling sfContext::getInsrtance().

NiKo