I'm trying to do a navigation. I have treelist for products.
Products
-product A
--product A.1
--product A.2
---product A.2.1
-product B
--product B.1
How can i show in my navigation only the parent. For example,
Products
-product A
-product B
I use cakephp 3.0. I make this treelist based on the tutorial blog.Can anyone help me?
This is my controller.
public function index()
{
$products = $this->Products->find()
->order(['lft' => 'ASC']);
$this->set(compact('products'));
$this->set('_serialize', ['products']);
}
let's suppose you don't have a root node in your tree.
I understand you want to retrieve all and just the nodes that are at the firt level. In this case you are looking for the nodes who have a NULL parent_id
$products = $this->Products->find('treeList')
->where(['parent_id IS NULL']);
instead if you have a root node which id is i.e. 1
$root_id = 1;
$products = $this->Products->find('treeList')
->where(['parent_id' => $root_id ]);