Monday, September 12, 2016

Simple CRUD using Bootstrap, Datatables,CodeIgniter, Jquery Ajax

Screenshots



I've search thru the web about CRUD in PHP jquery Ajax using modal form and i can say all the snippets i find is not accurate and helpful  so i decided to share my own snippets to you guys. 

In this tutorial we will be using Codeigniter Datatables, Jquery, Bootstrap,  Xampp for local webserver and  a little bit of commonsense. 

First of all download all the components to complete this project. I supposed you guys have the knowledge how to get this component and make it run. Follow the link on the above components and you will be alright.

I will not be discussing here how to install and set up codeigniter. You can follow this detailed User Guide from codeIgniter.


Lets Start Coding.

File Structure:

Now go to your Htdocs folder and make a folder called assets. Inside this folder we will make 2 new folder and name it js and css. Here we will paste the bootstrap jquery and datatables components.
assets/js folder
assets/css folder




Creating Database:

Open your localhost phpmyadmin and create a database named project.













Code Igniter Database Settings:



I'll make it a little simpler  lest skip the migration on CodeIgniter. Let's create a table from your database name project.

Table name: products










Column
prod_id = int, auto increment, primary key
prod_name{type: varchar, constraint:100}
prod_cost {type: decimal, constraint:65,2}
prod_stocks {type: INT}
prod_type {type:varchar, constraint:150}
prod_date_add {type: datetime , default: currenttimestamp}


in codeigniter create a model.Here we will create function for all the database interaction. I created a model name Project_model below is the code.

 Model Project_model.php 




Controller MycrudProject.php




HTML Views Folder 




 Jquery assets/js/project.js



 
 For more details download the Project file on this link Comment down below your questions and i'll be happy to answer. Happy coding.