/** * It's useful if you want to define a customized authorization logic. * How to use this method, for example? * * In Models: * ========== * class Event extends CActiveRecord { * public function behaviors() * { * return array( * 'QAuthCheckable' => array( * 'class' => 'application.modules.permission.components.QAuthCheckable' * ), * ); * } * public function isAllowed($user, $rule_name) { * // custom logic here * return true; * } * } * * In Controllers or elsewhere (e.g: views, widgets, etc): * ======================================================= * class EventController extends Controller { * public function actionDemo() { * $myEvent = new Event(); * $myEvent->isAllowed($user, 'myrule'); // it returns true or false * } * } * * @param User $user The user object. * @param string $ruleName The rule. * @return boolean True or false, if the user is authorized or not. */ public function isAllowed($user, $ruleName) { $ret_val = false; if (isset($user) && isset($ruleName)) { QAuthManager::setCacheEnabled(true); if (QAuthManager::hasAccess($user, $ruleName, $this->owner->tableName(), $this->owner->id)) { $ret_val = true; } } return $ret_val; }
/** * This method allows you to specify if queries (results) will be cached or not. * * @param boolean $enabled It turns the cache on/off. * @return boolean It returns true if the cache is enabled, false otherwise. * * @see CFileCache */ public static function setCacheEnabled($enabled) { if (isset($enabled) && is_bool($enabled)) { self::$_cacheEnabled = $enabled; } return self::isCacheEnabled(); }