CodeIgniter Tutorial
Home
CodeIgniter Installation
CodeIgniter Configuration
CodeIgniter Features
CodeIgniter URL
CodeIgniter Model
CodeIgniter View
CodeIgniter Controller
CodeIgniter Helper
CodeIgniter Library
CodeIgniter Session
CodeIgniter Flashdata
CodeIgniter Tempdata
CodeIgniter Example
CodeIgniter File Uploading
Form Validation
CodeIgniter Insert Data
CodeIgniter Display Data
CodeIgniter Delete Data
CodeIgniter Update Data
CodeIgniter Send Email
Create CodeIgniter Model
The Model represents your data structures. Usually your model classes will contain functions like retrieve, insert, and update information in your database. It is stored in application/models.
<?php class Model_name extends CI_Model{ public function __construct() { parent::__construct(); } public function save() { // Query Statement } ?>
CodeIgniter class name and file name same above your Model_name is your class then your file name will be Model_name.php
Model classes are stored in your application/models/ directory. They can be nested within sub folders if you want this type of organization.
The basic formate for a model class is this:
class Model_name extends CI_Model { }
Where Model_name is the name of your class. CodeIgniter Class name must be the first letter is capital with the rest of the name lowercase. Make sure your class extends the CodeIgniter base Model class.
Loading Model :
Models are loaded in the conntroller's file with the following code line:$this->load->model("Model_name");