我已经在我的 cakePHP 应用程序上成功设置了 Auth 和 ACL。
怎么样,现在我想建立一个界面来管理 ACL、ARO 和 ACO
ARO 和 ACO 很容易使用树行为构建。ACL 怎么让我有点搞砸了……尤其是在定义模型关系时。
我已将我的 aco 和 aro 模型分别命名为 Myaco 和 Myaro,因为 Aco 和 Aro 已经被 AclComponent 占用。我的 ACL 模型是 Myacl。
Myaco 是一个“独立”对象,它与任何其他模型无关。Myaro“belongsTo”“客户”模型(这是我的“用户”模型)并定义如下:
//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 构建主“界面”,我想“查找('all')”ACL 记录,并将链接(递归)到“客户”级别 - 这样我就可以显示组和表中的实际客户aro
;所以我将recursive
Myacl 模型的参数设置为“2”
虽然从调试窗格的 SQL 查询来看 - 关系根本不正确。我在如何设置关系方面完全错了吗?
以下是 find('all') 调用中的基本 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
您可以从“客户”查询的数量和连接中看到 - 模型关系严重“偏离”了一些东西。
非常感谢任何建议或线索。谢谢,肯。