SlideShare a Scribd company logo
Basic Tutorial
Index
This is a tutorial with basic
instructions about CodeIgniter.



It’s purpose is to help someone
with no prior knowledge of
frameworks, to understand it’s
basic principles and how it
works.









Index
About Frameworks
About MVC
Intro to CodeIgniter
Controllers
Routes File
Models
Frameworks
Frameworks are abstract, reusable platforms where we can develop
our applications.

They help in writing reusable and better constructed code.
Their main characteristic is the MVC (Model – View – Control)
architecture pattern.
MVC
The MVC architecture pattern separates the representation
of data from the logic of the application.
The View is what the visitors of the web application see.
The Controller is responsible for handling the incoming
requests, validating input and showing the right view.
The Model is responsible for accessing the database or
executing other operations.
MVC
Controller
Gets incoming requests.
Displays the right View.
Communicates with the
model.

The Controller calls
the Model.

Points to a View and
carries data.
Triggers a Controller

The Model retrieves / creates the
data asked and returns them to the
Controller
Model
Queries the database.
Executes operations.
Gives data to controller.

View
What the visitors see.
Html pages with PHP.
Displays data from
Controller
What is CodeIgniter
CodeIgniter is a PHP framework, easy to learn, suitable for
beginners.
 It needs no extra configuration.
 You do not need to use the command line.

 It is extremely light.
 You don’t need to learn a templating language.
 It is suitable for small or big projects.

All in all, you just need to know some PHP to develop the
applications you want.
Intro to CodeIgniter
How does a Controller trigger?
Each Controller triggers by a certain URI.
What happens when a Controller is triggered?
It then calls a Model (if any data should be retrieved or created),
it finds the View that should be shown to the visitor and then it
returns that View with the corresponding data.
How does CI knows what Controller to trigger?
This is defined by routes. Routes is a PHP configuration file that
maps each URL of our web project to a Controller and a certain
function.
Intro to CodeIgniter
User enters the URI of
the project

CI gets the request and
checks the routes file to
find any matches.

If a match is found, it
triggers the right
Controller and function.

View and data is
represented to
the user.

After the data is retrieved
the Controller finds the
right View and returns it.

The Controller calls the
right Model to retrieve /
create the data needed.
Controllers – The Class
A controller in CI is basically a custom made class, which inherits from the
CI_Controller class.

class WELCOME extends CI_Controller {
}

Create a controller with name
“welcome.php”. The new
controller is located into
applications/controllers folder.

In every controller we create, the constructor method must be
declared. In the constructor we can load libraries, models, the
database, create session variables and generally define content that
will be used by all methods. The constructor must have the same
name as the class.
Controllers – The Constructor
public function WELCOME() {
parent::_construct();

The first function of the controller is
the constructor, where we can load…

$this->load->helper(‘url’);
$this->load->helper(‘file’);

… the helper libraries we may
need….

$this->load->database();

… the database of our project…

$this->load->model(‘welcome_model’);
}

… and the models we need.
Controllers – The Functions
Then we can write the functions of the controller, that will be triggered by
the system. The functions can either perform some operations (through
the model), load a view, or even both.

public function home () {
if (!file_exists(application/views/home.php)){
show_404();
}
$this->load->view(‘home’);
}

The most usual operation is
to check if a view file exists
and load it.
View files are located in
application/views folder.
Views are what the visitors
see.
In case it does not exist, a
404 error message is
displayed to the visitor.
Controllers – The Functions
public function home () {
if (!file_exists(application/views/home.php)){
show_404();
}
$data[‘files’]=$this->welcome_model->get_data();
$this->load->view(‘home’,$data);
}

In case we need to send some data to the view, we retrieve them by calling the right
function from the model and then load them with the view. In the above example, the
data is then accessible by the name “files” in the “home” view.
Routes File
The routes file contains the matches for the URIs and the Controllers /
Functions.
There is a default controller which is triggered from the Base URL of
our project (e.g. www.my_project.com).
$route[„default_controller‟]=“controller_name/function_name”;
So, if we try to access the www.my_project.com, the routes file
understands it as the default controller and triggers the controller and
function we define, e.g. the welcome controller and the home function.
$route[„default_controller‟]=“welcome/home”;
Routes File
There is a pattern which we have to follow in order to create mappings of
URIs and controllers / functions.
my_project.com/class/function/id/
The first segment is reserved for the controller class, the second for the
function and the third of any values we want to pass as arguments
(optional). In case we don’t want to follow this pattern, the URI handler
has to be reconfigured.
If we want to map another URI, we have to follow that pattern. In the
following example if the URI is www.my_project.com/welcome/blog, CI
triggers the welcome controller and the blog method.
$route[„welcome/blog‟]=“welcome/blog”;
Models – Class/ Constructor
In a model we perform some tasks such as execute database queries, read / write
files or perform other operations. The models are located in applications/models
folder.

class Welcome_model extends CI_Model {

Each model we create, extends from
the CI_Model.

public function _construct () {
$this->load->database();
}

At first we have to write the
constructor of the model. In the
constructor we load the database or
other helper libraries.

}
Models - Functions
class Welcome_model extends CI_Model {
public function get_data() {
$query=$this->db->get(….);
/* perform other operations */
return $files;
}
}

In a model function we can perform
any operation we need, and then
return the data to the corresponding
function in the controller.
End of tutorial
The previous topics complete a basic intro into CodeIgniter and how it
essentially works.
CodeIgniter supports helpers, which is essentially a collection of functions
in a category, for example the helper for working with files (read / write) is
“file” and libraries as form validation. All of these can come in handy and
help a lot in developing your projects.
The database class of CodeIgniter supports both traditional structures as
Active Records patterns. Also, someone could set up CodeIgniter to run
with Doctrine (ORM), a topic that will be presented in another tutorial.
For the complete CodeIgniter documentation visit here.
Thank you for reading my tutorial.

More Related Content

PPTX
Laravel overview
Obinna Akunne
 
PPTX
Introduction to Spring Framework
Serhat Can
 
PDF
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
PPT
Web engineering - MVC
Nosheen Qamar
 
PPTX
Web search Technologies
Abdul Sami Kharal
 
PDF
Clean Architecture Applications in Python
Subhash Bhushan
 
PDF
Introduction To CodeIgniter
Muhammad Hafiz Hasan
 
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 
Laravel overview
Obinna Akunne
 
Introduction to Spring Framework
Serhat Can
 
Laravel Introduction
Ahmad Shah Hafizan Hamidin
 
Web engineering - MVC
Nosheen Qamar
 
Web search Technologies
Abdul Sami Kharal
 
Clean Architecture Applications in Python
Subhash Bhushan
 
Introduction To CodeIgniter
Muhammad Hafiz Hasan
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Dilouar Hossain
 

What's hot (20)

PPTX
Laravel introduction
Simon Funk
 
PPTX
Introduction to mvc architecture
ravindraquicsolv
 
PPTX
State management
Iblesoft
 
PPT
MVC ppt presentation
Bhavin Shah
 
PPTX
Introduction to Web Architecture
Chamnap Chhorn
 
PDF
Model View Controller (MVC)
Javier Antonio Humarán Peñuñuri
 
PPTX
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
Rishikese MR
 
PPTX
REST API
Tofazzal Ahmed
 
PPTX
laravel.pptx
asif290119
 
PPT
Web Servers (ppt)
webhostingguy
 
PPTX
An Overview of Web Services: SOAP and REST
Ram Awadh Prasad, PMP
 
PPTX
Introduction to laravel framework
Ahmad Fatoni
 
PDF
Laravel presentation
Toufiq Mahmud
 
PPT
Asp.net
Dinesh kumar
 
PDF
Vue.js
Jadson Santos
 
PPTX
MVVM ( Model View ViewModel )
Ahmed Emad
 
PPT
Understanding linq
Anand Kumar Rajana
 
PDF
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
PPTX
Introduction to ASP.NET
Rajkumarsoy
 
PPT
Asp.net basic
Neelesh Shukla
 
Laravel introduction
Simon Funk
 
Introduction to mvc architecture
ravindraquicsolv
 
State management
Iblesoft
 
MVC ppt presentation
Bhavin Shah
 
Introduction to Web Architecture
Chamnap Chhorn
 
Model View Controller (MVC)
Javier Antonio Humarán Peñuñuri
 
OVERVIEW OF FACEBOOK SCALABLE ARCHITECTURE.
Rishikese MR
 
REST API
Tofazzal Ahmed
 
laravel.pptx
asif290119
 
Web Servers (ppt)
webhostingguy
 
An Overview of Web Services: SOAP and REST
Ram Awadh Prasad, PMP
 
Introduction to laravel framework
Ahmad Fatoni
 
Laravel presentation
Toufiq Mahmud
 
Asp.net
Dinesh kumar
 
MVVM ( Model View ViewModel )
Ahmed Emad
 
Understanding linq
Anand Kumar Rajana
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
Edureka!
 
Introduction to ASP.NET
Rajkumarsoy
 
Asp.net basic
Neelesh Shukla
 
Ad

Viewers also liked (7)

PDF
Building RESTtful services in MEAN
Madhukara Phatak
 
PDF
Top 100 PHP Questions and Answers
iimjobs and hirist
 
PDF
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
PDF
Javascript Best Practices
Christian Heilmann
 
PPTX
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
PPT
PHP - Introduction to PHP MySQL Joins and SQL Functions
Vibrant Technologies & Computers
 
PPT
Codeigniter
minhrau111
 
Building RESTtful services in MEAN
Madhukara Phatak
 
Top 100 PHP Questions and Answers
iimjobs and hirist
 
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
Javascript Best Practices
Christian Heilmann
 
Mysql Crud, Php Mysql, php, sql
Aimal Miakhel
 
PHP - Introduction to PHP MySQL Joins and SQL Functions
Vibrant Technologies & Computers
 
Codeigniter
minhrau111
 
Ad

Similar to CodeIgniter 101 Tutorial (20)

DOCX
LearningMVCWithLINQToSQL
Akhil Mittal
 
PDF
Mvc4 crud operations.-kemuning senja
alifha12
 
PDF
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
PDF
Get things done with Yii - quickly build webapplications
Giuliano Iacobelli
 
PPTX
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
dioduong345
 
PPTX
Creating Single Page Web App using Backbone JS
Akshay Mathur
 
PDF
Jinal desai .net
rohitkumar1987in
 
PDF
Folio3 - An Introduction to PHP Yii
Folio3 Software
 
PPTX
Spring mvc
nagarajupatangay
 
PDF
MVC in PHP
Vineet Kumar Saini
 
PDF
IRJET- Lightweight MVC Framework in PHP
IRJET Journal
 
PDF
Principles of MVC for Rails Developers
Edureka!
 
PPTX
MVC 4
Vasilios Kuznos
 
PPT
Yii php framework_honey
Honeyson Joseph
 
PPTX
Sitecore MVC (User Group Conference, May 23rd 2014)
Ruud van Falier
 
PDF
How to Create and Load Model in Laravel
Yogesh singh
 
DOC
Rails notification
baran19901990
 
PPT
AspMVC4 start101
Rich Helton
 
PPTX
Sitecore MVC (London User Group, April 29th 2014)
Ruud van Falier
 
PDF
Code igniter - A brief introduction
Commit University
 
LearningMVCWithLINQToSQL
Akhil Mittal
 
Mvc4 crud operations.-kemuning senja
alifha12
 
Mvc interview questions – deep dive jinal desai
jinaldesailive
 
Get things done with Yii - quickly build webapplications
Giuliano Iacobelli
 
8-9-10. ASP_updated8-9-10. ASP_updated8-9-10. ASP_updated
dioduong345
 
Creating Single Page Web App using Backbone JS
Akshay Mathur
 
Jinal desai .net
rohitkumar1987in
 
Folio3 - An Introduction to PHP Yii
Folio3 Software
 
Spring mvc
nagarajupatangay
 
MVC in PHP
Vineet Kumar Saini
 
IRJET- Lightweight MVC Framework in PHP
IRJET Journal
 
Principles of MVC for Rails Developers
Edureka!
 
Yii php framework_honey
Honeyson Joseph
 
Sitecore MVC (User Group Conference, May 23rd 2014)
Ruud van Falier
 
How to Create and Load Model in Laravel
Yogesh singh
 
Rails notification
baran19901990
 
AspMVC4 start101
Rich Helton
 
Sitecore MVC (London User Group, April 29th 2014)
Ruud van Falier
 
Code igniter - A brief introduction
Commit University
 

Recently uploaded (20)

PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
PDF
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
PDF
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
PPTX
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Smart Infrastructure and Automation through IoT Sensors
Rejig Digital
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Automating ArcGIS Content Discovery with FME: A Real World Use Case
Safe Software
 
Orbitly Pitch Deck|A Mission-Driven Platform for Side Project Collaboration (...
zz41354899
 
Chapter 1 Introduction to CV and IP Lecture Note.pdf
Getnet Tigabie Askale -(GM)
 
How to Build a Scalable Micro-Investing Platform in 2025 - A Founder’s Guide ...
Third Rock Techkno
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 

CodeIgniter 101 Tutorial

  • 2. Index This is a tutorial with basic instructions about CodeIgniter.  It’s purpose is to help someone with no prior knowledge of frameworks, to understand it’s basic principles and how it works.      Index About Frameworks About MVC Intro to CodeIgniter Controllers Routes File Models
  • 3. Frameworks Frameworks are abstract, reusable platforms where we can develop our applications. They help in writing reusable and better constructed code. Their main characteristic is the MVC (Model – View – Control) architecture pattern.
  • 4. MVC The MVC architecture pattern separates the representation of data from the logic of the application. The View is what the visitors of the web application see. The Controller is responsible for handling the incoming requests, validating input and showing the right view. The Model is responsible for accessing the database or executing other operations.
  • 5. MVC Controller Gets incoming requests. Displays the right View. Communicates with the model. The Controller calls the Model. Points to a View and carries data. Triggers a Controller The Model retrieves / creates the data asked and returns them to the Controller Model Queries the database. Executes operations. Gives data to controller. View What the visitors see. Html pages with PHP. Displays data from Controller
  • 6. What is CodeIgniter CodeIgniter is a PHP framework, easy to learn, suitable for beginners.  It needs no extra configuration.  You do not need to use the command line.  It is extremely light.  You don’t need to learn a templating language.  It is suitable for small or big projects. All in all, you just need to know some PHP to develop the applications you want.
  • 7. Intro to CodeIgniter How does a Controller trigger? Each Controller triggers by a certain URI. What happens when a Controller is triggered? It then calls a Model (if any data should be retrieved or created), it finds the View that should be shown to the visitor and then it returns that View with the corresponding data. How does CI knows what Controller to trigger? This is defined by routes. Routes is a PHP configuration file that maps each URL of our web project to a Controller and a certain function.
  • 8. Intro to CodeIgniter User enters the URI of the project CI gets the request and checks the routes file to find any matches. If a match is found, it triggers the right Controller and function. View and data is represented to the user. After the data is retrieved the Controller finds the right View and returns it. The Controller calls the right Model to retrieve / create the data needed.
  • 9. Controllers – The Class A controller in CI is basically a custom made class, which inherits from the CI_Controller class. class WELCOME extends CI_Controller { } Create a controller with name “welcome.php”. The new controller is located into applications/controllers folder. In every controller we create, the constructor method must be declared. In the constructor we can load libraries, models, the database, create session variables and generally define content that will be used by all methods. The constructor must have the same name as the class.
  • 10. Controllers – The Constructor public function WELCOME() { parent::_construct(); The first function of the controller is the constructor, where we can load… $this->load->helper(‘url’); $this->load->helper(‘file’); … the helper libraries we may need…. $this->load->database(); … the database of our project… $this->load->model(‘welcome_model’); } … and the models we need.
  • 11. Controllers – The Functions Then we can write the functions of the controller, that will be triggered by the system. The functions can either perform some operations (through the model), load a view, or even both. public function home () { if (!file_exists(application/views/home.php)){ show_404(); } $this->load->view(‘home’); } The most usual operation is to check if a view file exists and load it. View files are located in application/views folder. Views are what the visitors see. In case it does not exist, a 404 error message is displayed to the visitor.
  • 12. Controllers – The Functions public function home () { if (!file_exists(application/views/home.php)){ show_404(); } $data[‘files’]=$this->welcome_model->get_data(); $this->load->view(‘home’,$data); } In case we need to send some data to the view, we retrieve them by calling the right function from the model and then load them with the view. In the above example, the data is then accessible by the name “files” in the “home” view.
  • 13. Routes File The routes file contains the matches for the URIs and the Controllers / Functions. There is a default controller which is triggered from the Base URL of our project (e.g. www.my_project.com). $route[„default_controller‟]=“controller_name/function_name”; So, if we try to access the www.my_project.com, the routes file understands it as the default controller and triggers the controller and function we define, e.g. the welcome controller and the home function. $route[„default_controller‟]=“welcome/home”;
  • 14. Routes File There is a pattern which we have to follow in order to create mappings of URIs and controllers / functions. my_project.com/class/function/id/ The first segment is reserved for the controller class, the second for the function and the third of any values we want to pass as arguments (optional). In case we don’t want to follow this pattern, the URI handler has to be reconfigured. If we want to map another URI, we have to follow that pattern. In the following example if the URI is www.my_project.com/welcome/blog, CI triggers the welcome controller and the blog method. $route[„welcome/blog‟]=“welcome/blog”;
  • 15. Models – Class/ Constructor In a model we perform some tasks such as execute database queries, read / write files or perform other operations. The models are located in applications/models folder. class Welcome_model extends CI_Model { Each model we create, extends from the CI_Model. public function _construct () { $this->load->database(); } At first we have to write the constructor of the model. In the constructor we load the database or other helper libraries. }
  • 16. Models - Functions class Welcome_model extends CI_Model { public function get_data() { $query=$this->db->get(….); /* perform other operations */ return $files; } } In a model function we can perform any operation we need, and then return the data to the corresponding function in the controller.
  • 17. End of tutorial The previous topics complete a basic intro into CodeIgniter and how it essentially works. CodeIgniter supports helpers, which is essentially a collection of functions in a category, for example the helper for working with files (read / write) is “file” and libraries as form validation. All of these can come in handy and help a lot in developing your projects. The database class of CodeIgniter supports both traditional structures as Active Records patterns. Also, someone could set up CodeIgniter to run with Doctrine (ORM), a topic that will be presented in another tutorial. For the complete CodeIgniter documentation visit here. Thank you for reading my tutorial.