2

I use Symfony 1.4, Doctrine 1.2 and sfDoctrineGuardPlugin. In actions.class.php i have:

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

if i am logged in this work good, but if i logout then i have error:

Fatal error: Call to a member function getId() on a non-object in

I tried:

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

but i have error:

Fatal error: Call to a member function isAuthenticated() on a non-object in

Beyed Black
  • 57
  • 1
  • 5

1 Answers1

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

The isAuthenticated() method is for the sfUser class, not sfGuardUser. And you can only access the sfGuardUser class via sfUser if the user is authenticated.

Tom
  • 30,090
  • 27
  • 90
  • 124
  • thanks! now in template Success i should use isset($id) same as in clear php? in symfony to do it differently? – Beyed Black Jul 02 '11 at 13:12
  • @Beyed Black: isset() is fine. Just make sure you pass the variable to the template as "$this->id", and you can then do isset($id). – Tom Jul 02 '11 at 15:48