It’s fairly common to want to store hierarchical data in a database table. Examples of such data might be categories with unlimited subcategories, data related to a multilevel menu system or a literal representation of hierarchy such as is used to store access control objects with ACL logic.

Setting up CakePHP

The CakePHP book describes how to set up an tree behavior example in CakePHP. Bancha automatically recognizes the TreeBeavior and behaves accordingly. 

The only thing you have to do is to augment the default controller index method. In this example below we create a index method for a model called "Task":

class TasksController extends AppController {
 * Returns the tasks in a tree structure, used by Bancha
 * @return void
	public function index() {
		return $this->Task->find('threaded');

See also our tree example.


Add a comment