我在表中有CakePHP 1.3
多树,对于moveup
和movedown
,我设置
$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
您应该在'type'字段而不是'parent_id'字段上确定作用域。每次都需要根据要使用的子树来设置范围。
$this->{$this->nodeType}->Behaviors->attach('Tree', array(
'scope' => array(
'Category.type' => $this->nodeType,
),
));