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();
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();
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