문제

For example I have this implementation of the assert method in the class derived from Zend_Acl_Assert_Interface.

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

It checks two conditions: user has enought money and user has enought rating. How to display error message to make user know which condition is failed when isAllowed method returns only bool?

도움이 되었습니까?

해결책

simply check them one by one

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

you can retrieve acl errors anywhere in your applicating by Zend_Registry::get('acl_error') ; and show it to user as you like.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top