Warning: Declaration of relatedpostsCPWidget::update($new_instance) should be compatible with WP_Widget::update($new_instance, $old_instance) in /home/nrtechweb/public_html/wp-content/plugins/related-post-widget-side/related-post-widget-side.php on line 53

Warning: Cannot modify header information - headers already sent by (output started at /home/nrtechweb/public_html/wp-content/plugins/related-post-widget-side/related-post-widget-side.php:53) in /home/nrtechweb/public_html/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 649

Warning: Cannot modify header information - headers already sent by (output started at /home/nrtechweb/public_html/wp-content/plugins/related-post-widget-side/related-post-widget-side.php:53) in /home/nrtechweb/public_html/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 666

Warning: Cannot modify header information - headers already sent by (output started at /home/nrtechweb/public_html/wp-content/plugins/related-post-widget-side/related-post-widget-side.php:53) in /home/nrtechweb/public_html/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 673

Warning: Cannot modify header information - headers already sent by (output started at /home/nrtechweb/public_html/wp-content/plugins/related-post-widget-side/related-post-widget-side.php:53) in /home/nrtechweb/public_html/wp-content/plugins/cleantalk-spam-protect/cleantalk.php on line 679
Custom category tree structure in Cakephp - NR Tech Web Solution | NR Tech Web Solution

Blog

Custom category tree structure in Cakephp

Custom category  tree structure in Cakephp

Hi Friends,

Today i am going to explain Category Parent Child deep hierarchy in cakephp system, I think this is very useful functionality can be use in e-commerce, classfied  and news based websites  because these type of website have many more categories with deep hierarchy .

I am writing this post because i have created many websites and every time i needed to create such type of functionality for each system so i thought that i should write a post that will help for many developers that are facing such type of functionality.

So lets start with some steps :

We need some pages of Cakephp like

  1. Controller
  2. Model
  3. view
  4. webroots
  5. Categories mysql table with defined structure

First of all i am assuming that we have a database  that have a table named “categories“, and this mysql table have three columns.
id         name        parent_id
Or if you have not categories table then just use this code

You can import categories table and its structure and its data as well.
Steps: 2)
Now go to Model folder that can be found in app folder like this app/Model and create a php file called Category.php

Steps: 3) Go to Controller folder and this folder is located in app/Controller path so now you have to create a controller file called pageController(its defalt file) or you can create any controller file here but now i am using pageController.php so you can use my code

Steps: 4)
Lets go to View folder ,i am managing its view using a element called header.ctp that is located in app/View/Elements/
Now we are going to render its view so i used a jquery tree plugin that takes json array.

Now we need to add some jquery treeview plugin css and js file in cakephp layout file that located in app/View/Layouts and i am using default.ctp file for now so just open this files it is already exist for each cakephp setup.

Okay so last srep is to place jquery plugin js and css file in webroot folder that is lacated in app/webroot
now you have to place js file in js folder and css file in css folder .
Thats it
I am going to add both js and css file here.
bootstrap-treeview.min.js


bootstrap-treeview.min.css
So just download these files and placed into webroot files now our Category Tree structured is ready.

Leave a Reply

Your email address will not be published. Required fields are marked *

Security *