Руководство>Компоненты ядра>Списки контроля доступа(ACL)>Defining Permissions: Cake's Database ACL>Checking Permissions: The ACL Component
Checking Permissions: The ACL Component
Let's use the AclComponent to make sure dwarves and elves can't remove things from the armory. At this point, we should be able to use the AclComponent to make a check between the ACOs and AROs we've created. The basic syntax for making a permissions check is:
Простой текст$this->Acl->check( $aro, $aco, $action = '*');
Let's give it a try inside a controller action:
Простой текстfunction index(){//These all return true:$this->Acl->check('warriors/Aragorn', 'Weapons');$this->Acl->check('warriors/Aragorn', 'Weapons', 'create');$this->Acl->check('warriors/Aragorn', 'Weapons', 'read');$this->Acl->check('warriors/Aragorn', 'Weapons', 'update');$this->Acl->check('warriors/Aragorn', 'Weapons', 'delete');//Remember, we can use the model/foreign key syntax//for our user AROs$this->Acl->check(array('model' => 'User', 'foreign_key' => 2356), 'Weapons');//These also return true:$result = $this->Acl->check('warriors/Legolas', 'Weapons', 'create');$result = $this->Acl->check('warriors/Gimli', 'Weapons', 'read');//But these return false:$result = $this->Acl->check('warriors/Legolas', 'Weapons');$result = $this->Acl->check('warriors/Gimli', 'Weapons', 'delete');}
The usage here is demonstrational, but hopefully you can see how checking like this can be used to decide whether or not to allow something to happen, show an error message, or redirect the user to a login.


Коментарии:
Добавить коментарий