2

我使用 Symfony 1.4、Doctrine 1.2 和 sfDoctrineGuardPlugin。在 actions.class.php 我有:

$this->idsfguard = $this->getUser()->getGuardUser()->getId();

如果我登录这项工作很好,但如果我注销然后我有错误:

致命错误:在非对象上调用成员函数 getId()

我试过:

  if ($this->getUser()->getGuardUser()->isAuthenticated()){
    $this->idsfguard = $this->getUser()->getGuardUser()->getId();
  }

但我有错误:

致命错误:在非对象上调用成员函数 isAuthenticated()

4

1 回答 1

3
if ($this->getUser()->isAuthenticated()) {
  $id = $this->getUser()->getGuardUser()->getId();
}

isAuthenticated()方法适用于 sfUser 类,而不是 sfGuardUser。如果用户经过身份验证,您只能通过 sfUser 访问 sfGuardUser 类。

于 2011-07-02T13:01:17.080 回答