Simply record the operation steps here for later review.
First, the introduction of auth/app/controller/appcontroller.php
PHP code
Class AppController extends Controller {public $components = Array (' Acl ', ' Auth ' = = Array ( ' Authorize ' = = Array ( ' Actions ' = = Array (' Actionpath ' = ' controllers ')) , ' Session ' ) ; Public $helpers = Array (' Html ', ' Form ', ' Session '); Public Function Beforefilter () { //configure authcomponent $this->auth->loginaction = Array ( ' Controller ' = ' users ', ' action ' = ' login ' ; $this->auth->logoutredirect = Array ( ' controller ' = ' users ', ' action ' = ' login ' ); $this->auth->loginredirect = Array ( ' controller ' = ' posts ', ' action ' = ' add ' ); } }
Second, generate ACL table
Bash code
./console/cake Schema Create Dbacl
Third, add groups and users
Set Model file/app/model/user.php
PHP code
Class User extends Appmodel {public $belongsTo = Array (' Group '); Public $actsAs = Array (' Acl ' = = Array (' type ' = ' = ' requester ')); Public Function ParentNode () { if (! $this->id && emptyempty ($this->data)) { return null; } if (isset ($this->data[' user '] [' group_id ')) { $groupId = $this->data[' user '] [' group_id ']; } else { $groupId = $this->field (' group_id '); } if (! $groupId) { return null; } Return Array (' Group ' = = Array (' id ' = $groupId)); } Public Function Bindnode ($user) { return array (' model ' = ' Group ', ' foreign_key ' = ' = ' $user [' user '] [' group_id ' ]); } }
File/app/model/group.php
PHP code
Class Group extends Appmodel {public $actsAs = Array (' Acl ' = = Array (' type ' = = ' requester ')); Public Function ParentNode () { return null; } }
Use bake to generate the MVC files for users, groups, add groups and users, and generate AROS data.
Iv. using Aclextras to generate ACO table data
Download Aclextras install to the/app/plugin/directory
PHP code
app/config/boostrap.php //... Cakeplugin::load (' Aclextras '); Use the Bash command to generate the available ACOs Data Bash code ./console/cake Aclextras.aclextras Aco_sync
V. Add login and Logout
PHP code
Login
Form->create (' User ', Array (' url ' = = Array (' controller ' = ' users ', ' action ' = ' login ') ) )); echo $this->form->input (' user.username '); echo $this->form->input (' User.password '); echo $this->form->end (' Login '); > ########### #分割线 ######## //Action public function login () { if ($this->session->read (' Auth.user ')) { $this->session->setflash (' logged in! '); return $this->redirect ('/'); } }
PHP code
Public Function Logout () { $this->redirect ($this->auth->logout ()); }
Vi. ACO-related
ACOs's display uses Treebehavior
PHP code
/app/model/aco.php file public $actsAs = Array (' Tree '); Public $displayField = ' Alias '; Output $this->aco->generatetreelist (null, NULL, NULL, ' );
Vii. Assignment of Rights
PHP code
Public Function Initdb () {$group = $this->user->group; Allow admins to everything $group->id = 1; $this->acl->allow ($group, ' controllers '); Allow managers to posts and widgets $group->id = 2; $this->acl->deny ($group, ' controllers '); $this->acl->allow ($group, ' controllers/posts '); $this->acl->allow ($group, ' controllers/widgets '); Allow users to only add and edit on posts and widgets $group->id = 3; $this->acl->deny ($group, ' controllers '); $this->acl->allow ($group, ' controllers/posts/add '); $this->acl->allow ($group, ' controllers/posts/edit '); $this->acl->allow ($group, ' controllers/widgets/add '); $this->acl->allow ($group, ' controllers/widgets/edit '); Allow basic users to log out $this->acl->allow ($group, ' controllers/users/logout '); We add an exit to avoid a ugly "missing views" error message echo "All done"; Exit }
Eight, finishing
PHP code /** * Custom Beforefilter */public function Beforefilter () { parent::beforefilter (); $this->auth->allow (' XXX '); $this->auth->allow (); }