Closed hgrami closed 6 years ago
public function uniqueValidator() {
$authManager = Yii::$app->authManager;
$value = $this->name;
if ($authManager->getRole($value) !== null || $authManager->getPermission($value) !== null) {
$message = Yii::t('yii', '{attribute} "{value}" has already been taken.');
$params = [
'attribute' => $this->getAttributeLabel('name'),
'value' => $value,
];
$this->addError('name', Yii::$app->getI18n()->format($message, $params, Yii::$app->language));
}
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['ruleName'], 'in',
'range' => array_keys(Yii::$app->authManager->getRules()),
'message' => Yii::t('rbac', 'Rule not exists')],
[['name'], 'required'],
[['name'], 'uniqueValidator', 'when' => function() {
return $this->isNewRecord || ($this->item->name != $this->name);
}],
[['description', 'data', 'ruleName'], 'default'],
[['name'], 'string', 'max' => 64]
];
}
Thanks for helping out)))))
That helped me in 2021!
Thanks. It's help me. But I made changes in amintado\rbac-plus\src\models\AuthItem.php
When creating a new role I get a call to undefined method Role::getDb(). To fix this issue modifications on johnitvn\rbac-plus\src\models\AuthItem.php needs to be made.
public function unique needs to be renamed as well under rules unique needs to be renamed as follow:
I suggest overriding model