【发布时间】:2014-06-17 17:40:31
【问题描述】:
使用 CakePHP 2.2.3 我的项目快完成了,现在要返回设置授权。
我正在实施 ACL,截断用户和组表以重新开始,运行命令以重新创建 aco/aro/aros_acos 表并按照教程进行操作。
当我创建一个组时,它会创建一个相应的 ARO 条目,但 lft 和 rght 字段为 NULL。我注释掉了用户/组模型和控制器中的所有其他代码以尝试缩小范围,但这似乎没有帮助。
我将在下面发布我的代码,为了空间,删除了 cmets 和验证。
组模型:
App::uses('AppModel', 'Model');
class Group extends AppModel {
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
return null;
}
public $hasMany = array(
'User' => array(
'className' => 'User',
'foreignKey' => 'group_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
);
}
用户模型:
App::uses('AppModel', 'Model');
App::uses('AuthComponent', 'Controller/Component');
class User extends AppModel {
//setup ACL settings and function
public $actsAs = array('Acl' => array('type' => 'requester'));
public function parentNode() {
if (!$this->id && empty($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;
} else {
return array('Group' => array('id' => $groupId));
}
} // end parentNode()
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
应用控制器:
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
//'Security',
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)/*,
'authenticate' => array(
'Form' => array(
'scope' => array('User.activated' => 1 )
)
) */
),
'Session'
);
public $helpers = array(
'Html',
'Text',
'Session',
'Form'
);
/* public function isAuthorized($user = null) {
return true;
} */
public function beforeFilter(){
$this->Auth->loginRedirect = array('controller' => 'products', 'action' => 'index' );
$this->Auth->logoutRedirect = array('controller' => 'products', 'action' => 'index');
$this->Auth->authError = 'You are not allowed to see that.';
}
我什至在全新安装的 cakephp 2.4.6 上进行了 ACL 实现,一切正常。我将项目并排进行比较,但在我的 ACL 设置中找不到差异
为什么我的 lft 和 rght 字段没有在我的 ARO 表中设置?
【问题讨论】:
标签: cakephp tree authorization acl cakephp-2.2