This PHPMaker 2024 project will show you how to implement Nested Set Model for data hierarchical and display it in TreeView.
The Nested Set Model is to number the Nodes according to a tree traversal, which visits each Node twice, assigning numbers in the order of visiting, and at both visits. This leaves two numbers for each Node, which are stored as two attributes.
Usually, we will use Nested Set Model to display the Breadcrumb Links in a website. As we have already known, this technique will only use one single table to display the data and its structure. In addition, there is only one Root or Parent that sits on top.
Unlike Closure Table that can store more than one Root or Parent that sits on top, the Nested Set Model only contains one Root or Parent that sits on top. That's why this can be implemented to display the Breadcrumb Links in a website, which will contain only one Home.
We will use Custom Files feature in PHPMaker project, that will display the TreeView in a separated page. It does not contain Header and Footer that generated by PHPMaker. Sometimes, we want to display the page in a separated layout. For this, then we can use Custom Files by disabling Include common files option of that Custom File.
Although it does not include the common files, we can still include some important PHP files, by writing some lines of PHP code inside the Content of Custom Files. The main reason for this, since we need to use the database connection settings that already defined in the generated configuration file or came from the Database_Connecting server event (if any).
By using this project, then we are able to do some CRUD (Create, Read, Update, and Delete) operations from the TreeView page visually. Simply right-click on the Node, then choose the related menu, whether to Create, Rename, Delete, Edit, Copy, Cut, and Paste.
We can also drag and drop a Node to another location easily. For example, we want to move a Node from one parent to another parent, or change the position of a Node. Any change that happens in TreeView will automatically update the Database accordingly. Sounds really cool, huh? ;-)
When a Node is being clicked/selected, then it will display the Breadcrumb Links of the current page, including the URL information that belongs to the current page. This is the main idea of the Nested Set Model, to display the complete Path or location of the certain Page.
This project also includes 4 menu items that will restore data in four scenario. The first scenario will populate only the root or Home node. The second scenario will populate some Nodes with two Parent below its root or Home node.
The third scenario will populate twenty Nodes. The fourth scenario will populate more than twenty Nodes with more complex Parent and Child combination. Of course, you may play with it after restoring the Data.