Cakephp 基于角色,每个控制器一个(Auth/ACL)
我有这个数据库:Cakephp 基于角色,每个控制器一个(Auth/ACL),cakephp,authentication,acl,Cakephp,Authentication,Acl,我有这个数据库: 角色(id、名称)->有许多用户 用户(id、角色\u id、用户名、密码)->属于角色 所以,通常我有三个角色:管理员、转售和客户。我为每个视图使用一个控制器,因为这样更容易管理视图。。然后我使用纯会话,你知道,我只在会话中存储所有用户数据,然后在每个控制器中检查角色是否与该角色对应 现在我想使用Auth/ACL组件,因为我厌倦了重新发明轮子。。问题是:我不知道如何对角色进行编程
角色
(id、名称)->有许多用户
用户
(id、角色\u id、用户名、密码)->属于角色
所以,通常我有三个角色:管理员、转售和客户。我为每个视图使用一个控制器,因为这样更容易管理视图。。然后我使用纯会话,你知道,我只在会话中存储所有用户数据,然后在每个控制器中检查角色是否与该角色对应
现在我想使用Auth/ACL组件,因为我厌倦了重新发明轮子。。问题是:我不知道如何对角色进行编程如果你给我垫脚石,我会很高兴的
这是我的密码:
AppController
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
public function beforeFilter() {
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->loginRedirect = array(
'controller' => 'HERE SHOULD BE THE ROLE CONTROLLER??',
'action' => 'add'
);
}
class UsersController extends AppController{
public $name = 'Users';
function index(){ }
function login(){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Your username or password was incorrect.'));
}
}
function logout(){
$this->Session->setFlash('Good-Bye');
$this->redirect($this->Auth->logout());
}
UsersController
class AppController extends Controller {
public $components = array(
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session'
);
public function beforeFilter() {
$this->Auth->loginAction = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->logoutRedirect = array(
'controller' => 'users',
'action' => 'login'
);
$this->Auth->loginRedirect = array(
'controller' => 'HERE SHOULD BE THE ROLE CONTROLLER??',
'action' => 'add'
);
}
class UsersController extends AppController{
public $name = 'Users';
function index(){ }
function login(){
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Your username or password was incorrect.'));
}
}
function logout(){
$this->Session->setFlash('Good-Bye');
$this->redirect($this->Auth->logout());
}
管理员控制器
(类似于转售或客户端控制器)
举个例子。核心ACL在99%的情况下都是过度使用。看起来不错,我会试试。