SlideShare a Scribd company logo
Codeigniter Framework
3. Model & Active record & Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Agenda
• Model component.
• Active record.
• Template.
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Model component
• What is Model.
• Create Model class.
• Load and call Model functions.
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
What is Model?
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
What is Model?
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Models are PHP classes that are designed
to work with information in your database.
• contains functions to insert, update, and
retrieve .
• Class names must have the first letter
capitalized with the rest of the name
lowercase.
Create Model class
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Create model class.
class Model_name extends CI_Model {
function __construct() {
parent::__construct();
}
function your_fanction(){
//your code
}}
Load and call Model functions
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• load model class.
$this->load->model(‘model_name');
• Call model functions.
$this->model_name->function();
Live Test
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Let’s Try It
Live!
Active record
• What is active record.
• Selecting data.
• Inserting data.
• Updating data.
• Deleting data.
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
What is Active record
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• This pattern allows information to be
retrieved, inserted, and updated in your
database with minimal scripting.
• allows you to create database
independent applications.
Selecting data
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Selecting data:
$query = $this->db->get(‘table_name');
foreach ($query->result() as $row){
echo $row->field_name;}
• Other Methods:
$this->db->select();
$this->db->where();
$this->db->join();
Inserting data
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Inserting data:
$this->db->insert(‘table‘,$data);
Updating data
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Updating data:
$this->db->where(‘id’, 4);
$this->db->update(‘my_table’,$data);
Or
$this->db->update(‘tabel’,$data,”id= $id”);
Deleting data
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Deleting data:
$this->db->where($id, 4);
$this->db->Delete();
Live Test
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Let’s Try It
Live!
Template
• Divide your template to 3 parts: Header,
Content and Footer.
• Put each one in a single view file
• Make main view page.
• Load the parts in the main view page.
• Enjoy :D
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Hello_world.php
<html>
<head> <title>Hello World!</title> </head>
<body>
<p>Hello world!</p>
</body>
</html>
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Display hello world page
class Hello_world extends CI_Controller {
public function index() {
$this->load->view('hello_world');
}
}
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Header.php
<html>
<head><title>Hello World!</title></head>
• Hellow_world.php
<p>Hello world!</p>
• Footer.php
</body></html>
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Display hello world page
class Hello_world extends CI_Controller {
public function index() {
$this->load->view('header');
$this->load->view('hello_world');
$this->load->view('footer');
}
}
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• template.php
<?php $this->load->view(‘header’);?>
<?php $this->load->view($main_content);?>
<?php $this->load->view(‘footer’);?>
Template
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
• Display hello world page
class Hello_world extends CI_Controller {
public function index() {
$data[‘main_content’]='hello_world’;
$this->load->view(‘template’, $data);
}
}
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Let’s Try It
Live!
Live Test
THANK YOU
Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
Questions?

More Related Content

PPSX
CodeIgniter L4 file upload & image manipulation & language
PPSX
CodeIgniter L2 helper & libraries & form validation
PPSX
CodeIgniter L5 email & user agent & security
PPSX
CodeIgniter L1 introduction to CodeIgniter framework
PPTX
PHP Lecture 4 - Working with form, GET and Post Methods
KEY
第49回Php勉強会@関東 Datasource
PPTX
Database Management - Lecture 4 - PHP and Mysql
KEY
Zf Zend Db by aida
CodeIgniter L4 file upload & image manipulation & language
CodeIgniter L2 helper & libraries & form validation
CodeIgniter L5 email & user agent & security
CodeIgniter L1 introduction to CodeIgniter framework
PHP Lecture 4 - Working with form, GET and Post Methods
第49回Php勉強会@関東 Datasource
Database Management - Lecture 4 - PHP and Mysql
Zf Zend Db by aida

What's hot (19)

PPTX
Resource Routing in ExpressionEngine
PPTX
Building a horizontally scalable API in php
PDF
Ruby on Rails 中級者を目指して - 大場寧子
KEY
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
PPTX
Deploy and Manage the Infrastructure Using Azure Resource Manager
PDF
Php workshop L04 database
PPTX
MS SQL Database basic
PDF
Php workshop L03 superglobals
PPTX
Comparing 30 MongoDB operations with Oracle SQL statements
PDF
PDF
Python Magic Methods: a practical example
PDF
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
PPTX
7. Php MongoDB editarea unui document
PDF
Introduction to Ruby
PDF
Assetic (OSCON)
PPTX
5. Php MongoDB vederea unui singur document
KEY
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
PDF
Python magicmethods
PPT
Jquery presentation
Resource Routing in ExpressionEngine
Building a horizontally scalable API in php
Ruby on Rails 中級者を目指して - 大場寧子
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Deploy and Manage the Infrastructure Using Azure Resource Manager
Php workshop L04 database
MS SQL Database basic
Php workshop L03 superglobals
Comparing 30 MongoDB operations with Oracle SQL statements
Python Magic Methods: a practical example
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
7. Php MongoDB editarea unui document
Introduction to Ruby
Assetic (OSCON)
5. Php MongoDB vederea unui singur document
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
Python magicmethods
Jquery presentation
Ad

Similar to CodeIgniter L3 model & active record & template (20)

ODP
Codegnitorppt
PDF
Introduction To CodeIgniter
PPTX
CodeIgniter Class Reference
PPT
Introduction To Code Igniter
PDF
Add edit delete in Codeigniter in PHP
PPTX
Codeigniter
PDF
Codeigniter
PPTX
PDF
CodeIgniter For Project : Lesson 106 - Model
PPT
PHP Frameworks and CodeIgniter
PPTX
CodeIgniter 101 Tutorial
PPTX
Codeigniter
PPTX
Introduction to codeigniter
KEY
CICONF 2012 - Don't Make Me Read Your Mind
PDF
Intro To Mvc Development In Php
DOCX
Codeigniter
PPT
Getting Started with Zend Framework
PPTX
CodeIgniter & MVC
PPT
Benefits of the CodeIgniter Framework
Codegnitorppt
Introduction To CodeIgniter
CodeIgniter Class Reference
Introduction To Code Igniter
Add edit delete in Codeigniter in PHP
Codeigniter
Codeigniter
CodeIgniter For Project : Lesson 106 - Model
PHP Frameworks and CodeIgniter
CodeIgniter 101 Tutorial
Codeigniter
Introduction to codeigniter
CICONF 2012 - Don't Make Me Read Your Mind
Intro To Mvc Development In Php
Codeigniter
Getting Started with Zend Framework
CodeIgniter & MVC
Benefits of the CodeIgniter Framework
Ad

More from Mohammad Tahsin Alshalabi (11)

PDF
NUMA optimized Parallel Breadth first Search on Multicore Single node System
PDF
Learning Management System in Damascus University-Information Technology Engi...
PPSX
Learning management system in information technology engineering faculty
PDF
Moodle documentation
PDF
Moodle plugins programing manual
PPSX
Comparison between web and mobile application requirements
PDF
Introduction to web services
PDF
Introduction to HTML5
PDF
Php workshop L02 php basics
PDF
Php workshop L01 CSS
PDF
Php workshop L0 Introduction
NUMA optimized Parallel Breadth first Search on Multicore Single node System
Learning Management System in Damascus University-Information Technology Engi...
Learning management system in information technology engineering faculty
Moodle documentation
Moodle plugins programing manual
Comparison between web and mobile application requirements
Introduction to web services
Introduction to HTML5
Php workshop L02 php basics
Php workshop L01 CSS
Php workshop L0 Introduction

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Cloud computing and distributed systems.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
MYSQL Presentation for SQL database connectivity
PPT
Teaching material agriculture food technology
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Network Security Unit 5.pdf for BCA BBA.
Cloud computing and distributed systems.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Review of recent advances in non-invasive hemoglobin estimation
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
MYSQL Presentation for SQL database connectivity
Teaching material agriculture food technology
Reach Out and Touch Someone: Haptics and Empathic Computing

CodeIgniter L3 model & active record & template

  • 1. Codeigniter Framework 3. Model & Active record & Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 2. Agenda • Model component. • Active record. • Template. Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 3. Model component • What is Model. • Create Model class. • Load and call Model functions. Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 4. What is Model? Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 5. What is Model? Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Models are PHP classes that are designed to work with information in your database. • contains functions to insert, update, and retrieve . • Class names must have the first letter capitalized with the rest of the name lowercase.
  • 6. Create Model class Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Create model class. class Model_name extends CI_Model { function __construct() { parent::__construct(); } function your_fanction(){ //your code }}
  • 7. Load and call Model functions Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • load model class. $this->load->model(‘model_name'); • Call model functions. $this->model_name->function();
  • 8. Live Test Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi Let’s Try It Live!
  • 9. Active record • What is active record. • Selecting data. • Inserting data. • Updating data. • Deleting data. Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 10. What is Active record Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • This pattern allows information to be retrieved, inserted, and updated in your database with minimal scripting. • allows you to create database independent applications.
  • 11. Selecting data Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Selecting data: $query = $this->db->get(‘table_name'); foreach ($query->result() as $row){ echo $row->field_name;} • Other Methods: $this->db->select(); $this->db->where(); $this->db->join();
  • 12. Inserting data Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Inserting data: $this->db->insert(‘table‘,$data);
  • 13. Updating data Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Updating data: $this->db->where(‘id’, 4); $this->db->update(‘my_table’,$data); Or $this->db->update(‘tabel’,$data,”id= $id”);
  • 14. Deleting data Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Deleting data: $this->db->where($id, 4); $this->db->Delete();
  • 15. Live Test Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi Let’s Try It Live!
  • 16. Template • Divide your template to 3 parts: Header, Content and Footer. • Put each one in a single view file • Make main view page. • Load the parts in the main view page. • Enjoy :D Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi
  • 17. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Hello_world.php <html> <head> <title>Hello World!</title> </head> <body> <p>Hello world!</p> </body> </html>
  • 18. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Display hello world page class Hello_world extends CI_Controller { public function index() { $this->load->view('hello_world'); } }
  • 19. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Header.php <html> <head><title>Hello World!</title></head> • Hellow_world.php <p>Hello world!</p> • Footer.php </body></html>
  • 20. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Display hello world page class Hello_world extends CI_Controller { public function index() { $this->load->view('header'); $this->load->view('hello_world'); $this->load->view('footer'); } }
  • 21. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • template.php <?php $this->load->view(‘header’);?> <?php $this->load->view($main_content);?> <?php $this->load->view(‘footer’);?>
  • 22. Template Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi • Display hello world page class Hello_world extends CI_Controller { public function index() { $data[‘main_content’]='hello_world’; $this->load->view(‘template’, $data); } }
  • 23. Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi Let’s Try It Live! Live Test
  • 24. THANK YOU Mhd Opada Al-Bosh & Mhd Tahsin Al-Shalabi Questions?