Archive

Archive for the ‘View’ Category

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

Mariusz Actions, Plugins, View

Accessing sfUser from template

February 3rd, 2009

It’s very easy - just use the $sf_user variable

Example.:

<?php if($sf_user->isAuthenticated()):? >
     < ?php echo "User is authenticated"?>
<?php else:?>
     <?php echo "User is not authenticated"?>
<?php endif?>

Mariusz View

Hello World!

February 3rd, 2009
 
<?php echo 'Hello World!'?>

Mariusz View