I have Groupdetails CRUD application.
In auth_item table, I created two roles namely
admin
fieldofficer
In auth_assignment, I assigned admin to Employee having id 29 and fieldofficer to Employee having id 13 and 28
In auth_rule, I added rule isfieldofficer
Now in models folder I create foll rule
<?php
namespace app\models;
use Yii;
use yii\rbac\Rule;
use app\models\Groupdetails;
/**
* Checks if authorID matches user passed via params
*/
class FieldofficerRule extends Rule
{
public $name = 'isfieldofficer';
/**
* @param string|int $user the user ID.
* @param Item $item the role or permission that this rule is associated with
* @param array $params parameters passed to ManagerInterface::checkAccess().
* @return bool a value indicating whether the rule permits the role or permission it is associated with.
*/
public function execute($user, $item, $params)
{
return isset($params['groupdetails']) ? $params['groupdetails']->EmpId == $user : false;
}
}
?>
Now in actionView()
I have foll
public function actionView($id)
{
$model = $this->findModel($id);
if(\Yii::$app->user->can('fieldofficer',['groupdetails'=>$model]))
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
else
{
throw new ForbiddenHttpException("You can't view other created groups details");
}
}
Now when I view, I got foll error:
Invalid Configuration – yii\base\InvalidConfigException
Rule not found: isfieldofficer