Различия
Показаны различия между двумя версиями страницы.
Следующая версия | Предыдущая версия | ||
yii2:user:rbac [2013/12/17 16:42] – внешнее изменение 127.0.0.1 | yii2:user:rbac [2016/08/07 00:11] (текущий) – [Ссылки / Видео] mirocow | ||
---|---|---|---|
Строка 1: | Строка 1: | ||
- | Ok. I hope someone will correct me if I'm wrong. | + | ====== RBAC ====== |
- | First af all, you modify your config (web.php), | ||
- | <code php> | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | </ | ||
- | Next, create the manager itself (app/ | + | ===== Расширения ===== |
- | <code php> | + | * https:// |
- | <?php | + | * https:// |
- | namespace app\components; | + | * https:// |
+ | * https:// | ||
- | use Yii; | + | ===== Ссылки / Видео ===== |
- | class PhpManager extends \yii\rbac\PhpManager | + | * http:// |
- | { | + | * http:// |
- | | + | * https:// |
- | { | + | * http:// |
- | if ($this-> | + | * http:// |
- | $this-> | + | * http:// |
+ | * http://www.elisdn.ru/blog/79/ | ||
+ | * http:// | ||
+ | * [[yii2: | ||
- | parent:: | ||
- | if (!Yii:: | ||
- | $this-> | ||
- | } | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | Now, the rules tree (@app/ | ||
- | |||
- | <code php> | ||
- | <?php | ||
- | use yii\rbac\Item; | ||
- | |||
- | return [ | ||
- | // HERE ARE YOUR MANAGEMENT TASKS | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | |||
- | // AND THE ROLES | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | |||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | |||
- | ]; | ||
- | </ | ||
- | |||
- | And voila, now you can add access control filters to controllers | ||
- | |||
- | <code php> | ||
- | public function behaviors() | ||
- | { | ||
- | return [ | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | ' | ||
- | [ | ||
- | ' | ||
- | ' | ||
- | ], | ||
- | ], | ||
- | ], | ||
- | ]; | ||
- | } | ||
- | </ | ||
- | |||
- | |||
- | Have fun. | ||
- | |||
- | PS. Right now I don't understand what is defaultRoles and how I can use them effectively. | ||
- | |||
- | Also, I think this can be done a little bit simpler. | ||
- | |||
- | I hope Yii2's core devs will shed some light on it. |