Accessing sfGuardPlugin user id.
September 29th, 2009
If you are using sfGuardPlugin all you need to get id of a user that is currently logged in is this:
In your actions.class.php
$user_id = $this->getUser()->getGuardUser()->getId();
But this will cause fatal error if the user is not authenticated. We can prevent this with isAuthenticated().
// /apps/frontend/lib/myUser.class.php
class myUser extends sfGuardSecurityUser { public function getUserId() { if($this->isAuthenticated()) return $this->getGuardUser()->getId(); else return 0; } }