CRUD – Codeigniter, Datatables, Ajax

Codeigniter is a PHP framework containing libraries, helpers, plugin-in and other resources. It will make the codes in PHP simple, quick and user-friendly.  It is lightweight and MVC programming technique to keep the business logic separate from the display logic. MVC stands for Model View Controller which is a software development method splitting the data layer (Model), the business logic (Controller) and the layout of the application (View). With the help of this framework, we’ll be building a simple CRUD with DataTables and Ajax.

Table of Content

  1. Introduction
  2. Configure Config File
  3. Configure Database
  4. Database Connection
  5. CRUD Demonstration
  6. Source Code

1. Introduction

CRUD stands for Create, Retrieve, Update, Delete to interact with the database table’s data.  As a web developer, CRUD is a usual work in your career and with the integration of datatables plugin, it will make the table more interactive, feasible and Better UI. You can download the source code and database SQL query at the end of this tutorial. You will have to make some changes in the source code to run the program

2. Configure Config file

In this part, Go to config.php file i.e. application/config/config.php and you must change base URL root to work the code properly without any errors. You will have to modify the base URL value in the config file to help the CodeIgniter to guess the protocol and path of your installation.

| Base Site URL
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
| http://localhost/crud_datatables_codeigniter
$config['base_url'] = 'http://localhost:9080/crud_datatables_codeigniter';


3. Configure the Database

Database Name: crud_datatables_codeigniter
Table Name: members
Table Column: id, fname, lname, age, contact, address

To create the database for this tutorial, either you can download the SQL file which is provided at the end of this tutorial or copy and paste this following SQL command into you MYSQL Database.

CREATE DATABASE `crud_datatables_codeigniter`;

CREATE TABLE `crud_datatables_codeigniter`.`members` (
  `fname` varchar(255) NOT NULL,
  `lname` varchar(255) NOT NULL,
  `age` varchar(255) NOT NULL,
  `contact` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)

4. Database Connection

In database.php file i.e. [application/config/database.php], contains a database connection. If you have different database name then change the database name in database.php file highlighted at below.

$db['default'] = array(
	'dsn'	=> '',
	'hostname' => 'localhost',
	'username' => 'root',
	'password' => '',
	'database' => 'crud_datatables_codeigniter',
	'dbdriver' => 'mysqli',
	'dbprefix' => '',
	'pconnect' => FALSE,
	'db_debug' => (ENVIRONMENT !== 'production'),
	'cache_on' => FALSE,
	'cachedir' => '',
	'char_set' => 'utf8',
	'dbcollat' => 'utf8_general_ci',
	'swap_pre' => '',
	'encrypt' => FALSE,
	'compress' => FALSE,
	'stricton' => FALSE,
	'failover' => array(),
	'save_queries' => TRUE

5. CRUD Demonstration

6. Source Code

6.1  Source Code

6.2 Database

4 thoughts on “CRUD – Codeigniter, Datatables, Ajax

  1. Hello,
    great template! But unfortunately I don’t get it work. There is still this error I can’t explain/change:

    An uncaught Exception was encountered

    Type: RuntimeException

    Message: Unable to locate the model you have specified: Model_member

    Filename: /users/username/www/system/core/Loader.php

    Line Number: 314


    File: /users/username/www/application/controllers/Welcome.php
    Line: 11
    Function: model

    File: /users/username/www/index.php
    Line: 292
    Function: require_once

    Does anyone has any ideas?

  2. I see you don’t monetize your website, don’t waste your
    traffic, you can earn additional cash every month because you’ve got
    hi quality content. If you want to know how to make extra money, search
    for: Boorfe’s tips best adsense alternative

Leave a Reply

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