【问题标题】:CakePHP multiple scopesCakePHP 多作用域
【发布时间】:2012-09-15 22:25:40
【问题描述】:

我在表中有CakePHP 1.3 多棵树,我设置了moveupmovedown

    $this->Category->Behaviors->attach('Tree', array(
        'scope' => array(
            'Category.parent_id' => $node['Category']['parent_id'],
        ),
    ));

而且记录也是按type分类的所以我也需要

            'Category.type' => $node['Category']['type'],

像这样没有任何区别。

这是我的数据示例:

id | parent_id | lft | rght | Title | type
1  | null      | 1   | 4    | Cat1  | categoory
2  | null      | 5   | 20   | Cat2  | categoory
3  | 2         | 6   | 13   |Cat2.1 | categoory
4  | 2         | 14  | 15   |Cat2.2 | categoory
5  | 2         | 16  | 17   | img1  | image
6  | 1         | 2   | 3    | img1  | image
7  | 2         | 18  | 19   | img2  | image
8  | 3         | 7   | 8    | Post1 | post
9  | 3         | 9   | 10   | Post2 | post
10 | 3         | 11  | 12   |Cat2.1.1| categoory

【问题讨论】:

  • 生成的sql查询是什么

标签: php cakephp tree cakephp-1.3 cakephp-model


【解决方案1】:

您应该在 'type' 字段而不是 'parent_id' 字段上确定范围。每次都需要根据要使用的子树设置范围。

$this->{$this->nodeType}->Behaviors->attach('Tree', array(
    'scope' => array(
        'Category.type' => $this->nodeType,
    ),
));

【讨论】:

  • 谢谢。一直在寻找更复杂的解决方案。我的坏
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-03-21
  • 1970-01-01
  • 2012-11-12
  • 1970-01-01
  • 1970-01-01
  • 2014-09-02
  • 1970-01-01
相关资源
最近更新 更多