2011-08-13 7 views
2

예를 들어 Zend_Acl_Assert_Interface에서 파생 된 클래스에 assert 메서드가 구현되어 있습니다.isAllowed 사용 후 오류 메시지 표시

function assert(
    Zend_Acl $acl, 
    Zend_Acl_Role_Interface $user = null, 
    Zend_Acl_Resource_Interface $item = null, 
    $privilege = null 
) { 
    if (!$user instanceof User) throw new Exception("…"); 
    if (!$item instanceof Item) throw new Exception("…"); 

    return 
     $user->money >= $item->price && 
     $user->rating >= $item->requiredRating; 
} 

두 가지 조건을 확인합니다. 사용자에게 충분한 돈이 있으며 사용자의 평점이 충분합니다. isAllowed 메서드가 bool 만 반환 할 때 어떤 조건이 실패했는지 사용자가 알 수 있도록 오류 메시지를 표시하는 방법?

답변

1

은 단순히 :: Zend_Registry에 의해 어디서든 applicating에서 ACL 오류를 검색 ('acl_error')을 얻을 수있는 하나의

$error = array(); 
if(!($user->money >= $item->price)) 
$error[] = "user money is less then price"; 

if(!($user->rating >= $item->requiredRating)) 
$error[] = "user rating less then required rating "; 

Zend_Registery::set('acl_error',$error); 
if(count($error) == 2) return false; 

return true; 

에 의해 그들에게 하나를 확인; 원하는대로 사용자에게 표시하십시오.

+0

좋은 해결책. 또한 $ acl-> getErrors() 메소드와 같은 것을 만들 수 있습니다. –

+0

@llya Golota 내 솔루션이 마음에 든다면 마킹하여 승인하십시오. –

+0

부작용이 있습니까? –

관련 문제