我现在正在与rbac yii2合作。 我定义了数据库中的所有角色和权限。 现在对我来说,问题是我应该在哪里检查访问规则? 例如,作者可以更新他自己的帖子。 我还在rule_name ='isAuthor'中保存了数据库中的规则。 但我对检查条件感到困惑,以访问自己的帖子。如何实现can()方法?
这里是我的actionRule:
<?php
public function actionRule(){
$auth = Yii::$app->authManager;
$rule = new \app\rbac\AuthorRule;
$auth->add($rule);
$updateMobile = $auth->createPermission('mobile/update');
// add the "updateOwnMobile" permission and associate the rule with it.
$updateOwnMobile = $auth->createPermission('updateOwnMobile');
$author = $auth->createPermission('author');
$updateOwnMobile->description = 'Update own mobile';
$updateOwnMobile->ruleName = $rule->name;
$auth->add($updateOwnMobile);
// "updateOwnMobile" will be used from "updatePost"
$auth->addChild($updateOwnMobile, $updateMobile);
// allow "author" to update their own posts
$auth->addChild($author, $updateOwnMobile);
}
?>
在哪里,我怎么能实现呢? in Controller?行为? 或其他地方?