Tagged: codeigniter tutorials

codeIgniter Libraries 0

CodeIgniter Libraries

Libraries used to provide common functionality that you want to be accessed by different parts of your app. They help provide a single point of entry that makes it simple to maintain consistency in business rules. They’re ideally used for creating focused, single-responsibility classes, like Benchmarking, UserObject, Article, etc.
Libraries are not just a file that must contain stand-alone information that can be passed from project to project, though that is the traditional role in CodeIgniter applications. It’s just not the only use for libraries.
It is present in both the system and the application folder.
Again, this is a class. (Note: your own libraries are not automatically included in the CI super-object, so you need to call CI resources in a different way.)
Load it like this: $this->load->library(‘class_name’);
Use it like this: $this->class_name->mainpage();
Notes on syntax:
No need to extend a base class, or for a constructor function.
This is enough:

class class_name()
function mainpage()
{ //code here }

Conceptually: Intended to hold your own code to extend CI functionality, or to create site-specific functionality.
List of Codeiginter Libraries
(Source : https://www.codeigniter.com/userguide3/libraries/index.html)


CodeIgniter Controllers

Controllers take care of moving the data between the model and the views and directing traffic
based on user actions. For example, when a user submits a form, the controller collects the data and
shuffles it off to the model, which should ensure the data is valid. The controller then tells the View
(or JavaScript layer) whether it was successful.
How Controllers Work 
Before I explain how, let’s  look at the routes.php file. This file of this  Application->Config>routes.php.
Routes.php File
when we browse http://localhost/codeigniter/, CI will look for the welcome controller and by default call the index method.
If we add an entry in routes.php

$route['home_page'] = 'welcome/home_page';

then browse url http://localhost/codeigniter/home_page, CI will look for a method name home_pagein Welcome controller.
Source code of Welcome controller

defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
	public function index()

 class Welcome extends CI_Controller:  class Welcome extends(inherit)  the CI core controller.
public function index() :  This function is executed when the home page  is browsed.

codeigniter Introduction 11

CodeIgniter Introduction

Codeigniter introduction
Codeigniter is a MVC Framework
What is MVC?
MVC Stands for Model, View, and Controller
MVC Architecture
CI MVC Architecture

  • Model work as back-end.
  • The model deals with back-end operations.
  • Fetch data from the database and send it to the controller


  • View work as front-end.
  • View deals with front-end operations.
  • Display data and capture user action
  • Send user action to the controller

The controller works as an intermediator between model and view.
Advantage of MVC

  • Reduce code flexibility
  • Code Reusability
  • Easy to manage
  • Code readability

What is the framework?
The framework is a collection of reusable libraries. which mean how to reuse the code.
why we use CodeIgniter

How to install CodeIgniter
Download the code from https://www.codeigniter.com/
Extract the zip file and paste it the root directory
Rename the directory(if you want)
run the CodeIgniter (https://localhost/directory_name)