查询 GROUP BY

<?phppublicfunctiontestgroup(){$this->loadModel('user');$this->user->recursive=-1;$result=$this->user->find('all',array('conditions'=>array('group_id'=>'1'),'fields'=>array('active','COUNT(active) as count'),'group'=>'active'));var_dump($result);die;}

cakephp-3-acl-example

A very simple CakePHP 3 ACL plugin usage example. This example is based on Simple Acl controlled Application for CakePHP 2. The differences are described in this document. The files in this repository contain the changes and implementations of functions discuessed below.

Getting started

Assuming you are using composer, get a copy of the latest cakephp release by running composer create-project --prefer-dist cakephp/app acl-example. This will create an empty CakePHP project in the acl-example directory. Answer YES when asked if folder permissions should be set.

Navigate to the CakePHP project directory (acl-example in this case) cd acl-example

Preparing to Add Auth

Add UsersController::login function

publicfunctionlogin(){if($this->request->is('post')){$user=$this->Auth->identify();if($user){$this->Auth->setUser($user);return$this->redirect($this->Auth->redirectUrl());}$this->Flash->error(__('Your username or password was incorrect.'));}}

Include and configure the AuthComponent and the AclComponent in the AppController

public$components=['Acl'=>['className'=>'Acl.Acl']];...$this->loadComponent('Auth',['authorize'=>['Acl.Actions'=>['actionPath'=>'controllers/']],'loginAction'=>['plugin'=>false,'controller'=>'Users','action'=>'login'],'loginRedirect'=>['plugin'=>false,'controller'=>'Posts','action'=>'index'],'logoutRedirect'=>['plugin'=>false,'controller'=>'Users','action'=>'login'],'unauthorizedRedirect'=>['controller'=>'Users','action'=>'login','prefix'=>false],'authError'=>'You are not authorized to access that location.','flash'=>['element'=>'error']]);

Add Temporary Auth Overrides

Temporarily allow access to UsersController and GroupsController so groups and users can be added. Add the following implementation of beforeFilter to src/Controllers/UsersController.php and src/Controllers/GroupsController.php:

First, find the IDs of each group you want to grant permissions on. There are several ways of doing this. Since we will be at the console anyway, the quickest way is probably to run bin/cake acl view aro to view the ARO tree. In this example, we will assume the Administrator, Manager, and User groups have IDs 1, 2, and 3 respectively.

Grant members of the Administrator group permission to everything

Run bin/cake acl grant Groups.1 controllers

Grant members of the Manager group permission to all actions in Posts and Widgets