Infinite dynamic Multi-level nested category with Codeigniter and MySQL

In my previous tutorial Infinite dynamic Multi-level nested category with PHP and MySQL , I wrote how to build a nested multilevel categories. So I have again written the same tutorial but this time with Codeigniter 3 framework.

Please follow below steps to find this example working


Netbeans 8.1
XAMPP in Windows
Codeigniter 3.0.6

Configure XAMPP and Netbeans

From Netbeans IDE go to Tools->Options. Click on PHP. Now on tab “General” browse the file for “PHP 5 Interpreter”. The php interpreter file generally placed inside the <physical drive in Windows OS>:xamppphpphp.exe

Configure Codeigniter and Netbeans

Create a new PHP project in Netbeans. Then remove the index.php file from the newly created project. Now copy the extracted files from Codeigniter 3.0.6 to the newly created project directory.

Directory Structure

A typical directory structure for the project would be as shown below. Here assests directory will contain static resources like css, js, images.

nested categories codeigniter

Final output in the browser

nested categories codeigniter

Now we will see how it happens step by step.

Step 1. Now modify <root directory>/application/config/autoload.php file for auto-loading html, url, file, form and session

Step 2. Go to location ci/application/config/database.php file and change database parameter values for below parameters

Step 3. Create a MySQL table in “roytuts” database

Step 4. Dump some data into database table – category

Step 5. Create a model file categorymodel.php under ci3/application/models directory with the below source code

Step 6. Create a controller file category.php under ci3/application/controllers with the following source code

Step 7. Create a view file category.php under ci3/application/views

Step 8. Modify file ci3/application/config/routes.php file

Step 9. If everything is fine then run the application. You will get the output in the browser.

That’s all. Thanks for reading.

Soumitra Roy Sarkar

I am a professional Web developer, Enterprise Application developer, Software Engineer and Blogger. Connect me on Twitter Facebook  Google Plus Linkedin

One Reply to “Infinite dynamic Multi-level nested category with Codeigniter and MySQL”

Leave a Reply

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