I ran into a rather complex problem and I need the tree behavior to help.
I have a table called nodes, this table already has a tree and this tree is used to build a menu.
Now we want to make it possible to create multiple menus so I made the node_menus and menus tables. So Nodes hasAndBelongsToMany Menus
However there is a slight problem, the menus are built but uses $this->Node->find('threaded') so sub menus are possible. All nodes can be used in several menus and all menus need a tree so the nodes can be ordered and sub menus can be created as well.
For that I was thinking about creating one table containing trees for each menu and link a node to each row in the tree table.
So basically I need a trees table with a Trees belongsTo Nodes relation. In this tree i have the fields menu_id, node_id, parent_id, lft and rght.
Now the question is, are multiple trees possible in one table? Say, I want the tree where menu_id is 15. Would it be possible to use find('threaded') with said ID that would return all the data and the Nodes related to the node_id‘s. Including all of the other core functions to create and manipulate the tree.
Is this possible? If not, does anyone have a better solution on how to make multiple menus where nodes can be places in multiple menus that can be ordered and threaded?
Think like the following, then you can do it with a single tree.
I’ve made a menu builder plugins for CakePHP, you can use it if you like 🙂
https://github.com/torifat/cake-menu_builder