我在cakePHP应用程序上成功地设置了Auth和ACL。使用CakePHP为ACL接口(gui)定义模型关系
如何,现在我想建立一个界面,用于管理ACL的,ARO的和ACO的
ARO的和ACO的地方很容易用树的行为来构建。 ACL总是让我有些困惑......特别是当它来定义模型关系时。
我已经分别命名我的aco和aro模型Myaco和Myaro,因为Aco和Aro已经使用了AclComponent。我的ACL模型是Myacl。
Myaco是一个“独立”的对象,它与任何其他模型都没有关系。 Myaro“属于关联”“客户”的模式(这是我的“用户”模式),并定义为这样:
//Myaro model
var $belongsTo = array('Customer'=> array(
'foreignKey' => 'foreign_key'
));
现在Myacl模型按我的理解,是一个$ hasAndBelongsToMany - > Myaco和Myaro自一个连接另外两个模型的表格; 因此我已经设定,这样的:
class Myacl extends AppModel {
var $useTable = 'aros_acos';
var $hasAndBelongsToMany = array(
'Myaro' => array(
'foreignKey' => 'aro_id',
'associationForeignKey' => 'id',
'joinTable' => 'aros_acos'
),
'Myaco' => array(
'foreignKey' => 'aco_id',
'associationForeignKey' => 'id',
'joinTable' => 'aros_acos'
),
);
}
我们打造为ACL的主要“接口”,我想“找到(‘所有’)” ACL记录,并有链接(递交)直至“客户”级别 - 以便我可以显示aro
表中的组和实际客户;所以我设置了recursive
参数设置为“2”为Myacl模型
虽然判断由调试窗格的SQL查询 - 的关系是不正确的所有.. 是我在我如何设置的关系完全错误?
这里距离发现( '全部')调用的基本的SQL查询:
从这个代码(在Myacl控制器):
$this->Myacl->recursive = 2;
$allRules = $this->Myacl->findAll();
的查询是:
1 DESCRIBE `aros` 7 7 13
2 DESCRIBE `acos` 7 7 1
3 DESCRIBE `aros_acos` 3 3 1
4 DESCRIBE `customers` 9 9 2
5 SELECT `Myacl`.`id`, `Myacl`.`aro_id`, `Myacl`.`aco_id` FROM `aros_acos` AS `Myacl` WHERE 1 = 1 ORDER BY `Myacl`.`id` ASC 9 9 0
6 SELECT `Myaro`.`id`, `Myaro`.`parent_id`, `Myaro`.`model`, `Myaro`.`foreign_key`, `Myaro`.`alias`, `Myaro`.`lft`, `Myaro`.`rght`, `ArosAco`.`id`, `ArosAco`.`aro_id`, `ArosAco`.`aco_id` FROM `aros` AS `Myaro` JOIN `aros_acos` AS `ArosAco` ON (`ArosAco`.`aro_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND `ArosAco`.`id` = `Myaro`.`id`) WHERE 1 = 1 9 9 0
7 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
8 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
9 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
10 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
11 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
12 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
13 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
14 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
15 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
16 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
17 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
18 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
19 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
20 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
21 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
22 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
23 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
24 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
25 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
26 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
27 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
28 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
29 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
30 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
31 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 1 1 1 0
32 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 2 1 1 0
33 SELECT `Customer`.`id`, `Customer`.`username`, `Customer`.`email`, `Customer`.`password`, `Customer`.`company_name`, `Customer`.`contact_person`, `Customer`.`contact_email`, `Customer`.`contact_phone`, `Customer`.`disabled` FROM `customers` AS `Customer` WHERE `Customer`.`id` = 4 1 1 0
34 SELECT `Myaco`.`id`, `Myaco`.`parent_id`, `Myaco`.`model`, `Myaco`.`foreign_key`, `Myaco`.`alias`, `Myaco`.`lft`, `Myaco`.`rght`, `ArosAco`.`id`, `ArosAco`.`aro_id`, `ArosAco`.`aco_id` FROM `acos` AS `Myaco` JOIN `aros_acos` AS `ArosAco` ON (`ArosAco`.`aco_id` IN (1, 2, 3, 4, 5, 6, 7, 8, 9) AND `ArosAco`.`id` = `Myaco`.`id`) WHERE 1 = 1
您可以从“客户”查询的数量以及来自联接的数量中看出,某些情况与型号关系严重“关闭”。
任何意见或建议,不胜感激。 谢谢, 肯。
@Ferco:谢谢你的答复,有点晚,但我已经知道了。我按照你的建议做了 - 同样的关系。谢谢! – Ken