SlideShare a Scribd company logo
1 of 24
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

What's hot

Resource Routing in ExpressionEngine
Resource Routing in ExpressionEngineResource Routing in ExpressionEngine
Resource Routing in ExpressionEngineMichaelRog
 
Building a horizontally scalable API in php
Building a horizontally scalable API in phpBuilding a horizontally scalable API in php
Building a horizontally scalable API in phpWade Womersley
 
Ruby on Rails 中級者を目指して - 大場寧子
Ruby on Rails 中級者を目指して - 大場寧子Ruby on Rails 中級者を目指して - 大場寧子
Ruby on Rails 中級者を目指して - 大場寧子Yasuko Ohba
 
Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Introduction to DBIx::Lite - Kyoto.pm tech talk #2
Introduction to DBIx::Lite - Kyoto.pm tech talk #2Hiroshi Shibamura
 
Deploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource ManagerDeploy and Manage the Infrastructure Using Azure Resource Manager
Deploy and Manage the Infrastructure Using Azure Resource ManagerGlobalLogic Ukraine
 
MS SQL Database basic
MS SQL Database basicMS SQL Database basic
MS SQL Database basicwali1195189
 
Comparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsComparing 30 MongoDB operations with Oracle SQL statements
Comparing 30 MongoDB operations with Oracle SQL statementsLucas Jellema
 
Python Magic Methods: a practical example
Python Magic Methods: a practical examplePython Magic Methods: a practical example
Python Magic Methods: a practical exampleNacho Gentile
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Comsysto Reply GmbH
 
7. Php MongoDB editarea unui document
7. Php MongoDB editarea unui document7. Php MongoDB editarea unui document
7. Php MongoDB editarea unui documentRazvan Raducanu, PhD
 
5. Php MongoDB vederea unui singur document
5. Php MongoDB vederea unui singur document5. Php MongoDB vederea unui singur document
5. Php MongoDB vederea unui singur documentRazvan Raducanu, PhD
 
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginator
2009-08-28 PHP Benelux BBQ: Advanced Usage Of Zend Paginatornorm2782
 
Python magicmethods
Python magicmethodsPython magicmethods
Python magicmethodsdreampuf
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationguest5d87aa6
 

What's hot (19)

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

Similar to CodeIgniter L3 model & active record & template

Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friendkikoalonsob
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::ManagerJay Shirley
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redisjimbojsb
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterPerrin Harkins
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao IntroductionBooch Lin
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...jaxLondonConference
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class ReferenceJamshid Hashimi
 
Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)mpvanwinkle
 
Banishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPBanishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPDavid Hayes
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Michelangelo van Dam
 

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

Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
Database API, your new friend
Database API, your new friendDatabase API, your new friend
Database API, your new friend
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
PHP and databases
PHP and databasesPHP and databases
PHP and databases
 
Scaling php applications with redis
Scaling php applications with redisScaling php applications with redis
Scaling php applications with redis
 
Scaling Databases with DBIx::Router
Scaling Databases with DBIx::RouterScaling Databases with DBIx::Router
Scaling Databases with DBIx::Router
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
GreenDao Introduction
GreenDao IntroductionGreenDao Introduction
GreenDao Introduction
 
Drupal7 dbtng
Drupal7  dbtngDrupal7  dbtng
Drupal7 dbtng
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
About Data::ObjectDriver
About Data::ObjectDriverAbout Data::ObjectDriver
About Data::ObjectDriver
 
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
Designing and Building a Graph Database Application - Ian Robinson (Neo Techn...
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Php summary
Php summaryPhp summary
Php summary
 
Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)Wordcamp Fayetteville Pods Presentation (PDF)
Wordcamp Fayetteville Pods Presentation (PDF)
 
php2.pptx
php2.pptxphp2.pptx
php2.pptx
 
Banishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPBanishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHP
 
Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010Advanced Php - Macq Electronique 2010
Advanced Php - Macq Electronique 2010
 

More from Mohammad Tahsin Alshalabi

More from Mohammad Tahsin Alshalabi (11)

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

Recently uploaded

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

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?