开发者

how to acess user session in sfDoctrineRoute with symfony?

how to acess user session in sfDoctrineRoute with开发者_如何学JAVA symfony ?

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

returns NULL

i cant access current user session in routing

Accessing user session from a custom routing class = bad response


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::getInstance().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜