2011-01-05 58 views

回答

0

当然可以。

要管理用户证书,sfBasicSecurityUser提供了几个方法:

// Add one or more credentials 
$user->addCredential('foo'); 
$user->addCredentials('foo', 'bar'); 

// Check if the user has a credential 
echo $user->hasCredential('foo');      => true 

// Check if the user has both credentials 
echo $user->hasCredential(array('foo', 'bar'));  => true 

// Check if the user has one of the credentials 
echo $user->hasCredential(array('foo', 'bar'), false); => true 

// Remove a credential 
$user->removeCredential('foo'); 
echo $user->hasCredential('foo');      => false 

// Remove all credentials (useful in the logout process) 
$user->clearCredentials(); 
echo $user->hasCredential('bar');      => false 

来源:Practical symfony - day 13 - The User

在你的行动,你可以访问用户对象具有的getUser()方法:

$user = $this->getUser(); 
相关问题