0

CakePHP アプリで Auth と ACL を正常にセットアップしました。

ACL、ARO、ACO を管理するためのインターフェイスを構築したい

ARO と ACO は、ツリーの動作を使用して非常に簡単に構築できます。ACL は、私を少し混乱させてしまいました...特に、モデル関係の定義に関しては。

Aco と Aro は既に AclComponent を使用しているため、私の aco と aro モデルにそれぞれ Myaco と Myaro という名前を付けました。私の ACL モデルは Myacl です。

Myaco は「スタンドアロン」オブジェクトであり、他のモデルとは関係ありません。Myaro "belongsTo" 'Customer' モデル (これは私の「ユーザー」モデル) であり、次のように定義されています。

//Myaro model
var $belongsTo = array('Customer'=> array(
                                        'foreignKey'    => 'foreign_key'
                                        ));

Myacl モデルは、私が理解しているように、$hasAndBelongsToMany -> Myaco と Myaro です。これは、他の 2 つのモデルを結合するテーブルであるためです。そのため、次のように設定しました。

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 レコードを「検索 ('all')」し、「顧客」レベルまでリンク (再帰) したいと考えました。これにより、グループとaroテーブルからの実際の顧客。recursiveMyaclモデルのパラメータを「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

「顧客」クエリの量と結合から、モデルの関係で何かが深刻に「ずれている」ことがわかります。

アドバイスやリードは大歓迎です。ありがとう、ケン。

4

1 に答える 1

1

私は ACL から始めたばかりですが、ACL の関係で間違っていると思います。aro hasAndBelongsToMany aco は、acl をそれらの間のスタブにします。したがって、acl のモデルを作成している場合は、begsTo aro と belongsTo aco が必要です。Aro と aco には hasMany acl が必要です。それが役立つことを願っています;D

于 2010-01-03T15:59:17.843 に答える