Closed fullflash closed 8 years ago
sorry my mistake. i have commented as access in config during some testing.
but i think this post with screens would be helpfull who has trouble with rules integration in yii2 admin.
Thanks for this excellent module by the way.
how we can post a variable to $params attrbute ? manually as in yii2 official rbac docs or there is some options in yii2 admin setting to data field or bizrule module ?
public function execute($user, $item, $params)
{
// return false;
return isset($params["news"]) ? $params["news"]->created_by==$user : false;
}
changed rule now it works model id passed by $params function argument is enough )
public function execute($user, $item, $params)
{
if(isset($params["id"])) {
$news_id = $params["id"];
$data = News::find()->select("created_by")->where(["id" => $news_id])->limit(1)->asArray()->one();
return isset($data) ? $user == $data["created_by"] : false;
}
return false;
}
Hi, @fullflash I have trouble in using RULE in this package can you give a clear demo example with code showing how to create a rule and after creating the rule then how to use it in coding. I need a complete example because I tried it very much but I am fail to implement it specially the $param and then calling the rule in code , I think you may be clear with my problem as from you posts it show that you have faced this problem and I think my problem is similar to yours. Thanks.
Hi, i have created AuthorRule under backend\rules with namescape backend\rules with public $name="authorRule"; inside class and overriding execute as described in official guide.
in yii2 admin create a rule with name: authorRule and classname: backend\rules\AuthorRule
added this rule to permission updateOwnNews updateOwnNews is a parent of updateNews permission as described in official docs. updatePost permission has route /news/update
there is a role author with updateOwnNews permission
but user with this author role update post that not created by him. On debugmode breakpoint in execute method just don't triggered. Rule class just not executed. what is wrong ?