Back to Top

Getting Started with CodeIgniter

Getting Started with CodeIgniter

Today I am going to cover small tutorial about CodeIgniter.CodeIgniter is a PHP framework for web application.Basically, CodeIgniter follows the most well-known Model, view and controllers (MVC) architecture. With CodeIgniter, you can write your code from the scratch and maintain some code design pattern which can reduce your development time and increase performance.

CodeIgniter is a simple, lightweight and robust framework which provide helpers, libraries and hook concepts.

Installations

Let’s Start from Installations:

Step 1:

First of all download latest version of CodeIgniter.After that extract zip folder and add that folder into the root directory.That’s it. your CodeIgniter set up is done.

Now let’s take a quick view of CodeIgniter folder structure.

Root Structure

Root directory of CodeIgniter mainly contains System, Application folder. System folder contains core code of code-igniter. We never work on system folders and its only for core files.

The main folder for us is Application in which we write code and its contain config, controllers, Models, views, helpers, hooks and libraries.see in below screen.

application

Now, we will dive in four directories which are mainly useful for basic coding in Codeigniter.

  1. Config: Config contains configuration settings and include some core libraries in which we need to change database configuration as per application.
  2. Controllers: Directory contains controllers.Its a intermediator between Models and Views.
  3. Models: Its contain all models of our application which can have a database information.Model class includes insert,update and retrieve queries.
  4. Views: Its for user view.Its contain template files of web page. Mainly view is for storing your html code and displaying it to the user

Step 2:

Next we will configure database details in database.php file which in application/config folder.
You need to change below code.

Step 3:

After configuring the database, run your application with URL http://localhost/ci/ and if you get below the screen, your application installed successfully.

Now it’s time to create simple Application with CodeIgniter.

A Simple Demo Application

We will create simple demo application which display category from the database table.

Step 1:

Let’s Create Category table and insert some categories over there.

Step 2:

After that create one new file “demo.php” in controllers folder and write below code inside demo.php

First we create class Demo which is controller class and extends core controller CI_Controller.Inside controller class, we have called __construct and default function index.

Step 3:

Create files m_demo.php in models and add below code over there

Step 4:

Create files v_demo.php in views and add below code overthere

Now type in the controller name in the web browser’s address bar as follows:

Say if we are running it in the local PC under localhost:

And Your code will give below OUTPUT

OUTPUT:

Also Read:
Image Upload in CodeIgniter
Codeigniter _remap function
Prepping Functions in CodeIgniter

That’s it.Hopefully, this post will helpful to get the basic idea about CodeIgniter. If you have any problem configuring CodeIgniter, Let me know via comments. Don’t forget to share this tutorial with others on Facebook & Google Plus.

Comments (5)

  1. […] More: Code Igniter Tutorial | Creative Dev […]

  2. it’s working, but the “echo ” in the controller seems strange, should be in the view?

  3. jafor iqbal says:

    Nice Tutorial
    Thanks brother

  4. Please mention the version of codeigniter in this tutorials..one of the problems with frameworks is with evey new version there are big changes.

  5. Since the admin of this site is working, no doubt very rapidly it will be famous,
    due to its quality contents.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Most Popular Posts