Answer the question
In order to leave comments, you need to log in
How can the data property of the yii\rbac\Item class be used?
The documentation says that there can be any mixed data attached to the current item.
This is clear. But how can this be applied in practice? I couldn't find any examples.
Answer the question
In order to leave comments, you need to log in
I did not use this miracle property, but you interested me, got into the kernel and dug up the following:
There is an addItem method in yii\rbac\DbManager
/**
* @inheritdoc
*/
protected function addItem($item)
{
$time = time();
if ($item->createdAt === null) {
$item->createdAt = $time;
}
if ($item->updatedAt === null) {
$item->updatedAt = $time;
}
$this->db->createCommand()
->insert($this->itemTable, [
'name' => $item->name,
'type' => $item->type,
'description' => $item->description,
'rule_name' => $item->ruleName,
'data' => $item->data === null ? null : serialize($item->data),
'created_at' => $item->createdAt,
'updated_at' => $item->updatedAt,
])->execute();
$this->invalidateCache();
return true;
}
$role = Yii::$app->authManager->createRole('admin');
$role->description = 'Администратор';
$role->data = ['roleColor'=>'#fff', 'razmer_sisek'=>5];
Yii::$app->authManager->add($role);
<?php
$role = Yii::$app->authManager->get('admin');
$bgcolor = $role->data['roleColor'];
?>
<body style="background-color:<?=$bgcolor?>;">
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question