how - > find('threaded')可以与cakephp 3.x一起使用

时间:2016-05-08 15:34:33

标签: cakephp tree cakephp-3.0

我正在尝试将树行为用于类别表。我刚刚使用蛋糕烘焙创建了modelcontrollercategoryTablecategory.php。它正在工作,但我想把所有的孩子都放在他的父母之下,看完蛋糕书后我才知道->find('threaded')可以做到这一点。但这是错误的。

错误是:

  

传递的变量不是数组或对象,而是使用空数组

完整查询是:

$parentCategory = $this->Category->ParentCategory->find('list', ['limit' => 200])->find('threaded');

它给出错误,但是如果我删除->find('threaded')然后没有错误,但它显示的数据与保存的顺序相同。

目前它的工作原理如下;

Parent 1
child 1
child 2

Parent 2
child 1
child 2
child 3(from parent 1)

虽然我想按以下方式显示

parent 1
child 1 
child 2
child 3

parent 2
child 1
child 2

1 个答案:

答案 0 :(得分:0)

怎么样:

$parentCategories = $this -> Categories -> ParentCategories -> find('treeList', ['limit' => 200]);

cakephp3中的所有模型必须是prulars

类别应为类别 ParentCategory 应为 ParentCategories