Model Class

Navigation:  Development > MVC (Model View Controller) > Model >

Model Class

Previous pageReturn to chapter overviewNext page

Each Model has a class to maintain the connection. Generally we creates all model class in below location:
 
/development/models

 

Each model as a Name that we used in class name as well as save in a member variable. Model class always extends appRain_Base_Model. See below example

 
// Model Name : page
// Class Name: pageModel
class pageModel extends appRain_Base_Model
{
  public $name = "Page";
}

 

Model Version and Table Name is a vital entity to work with database. Assign false in $db_table if there is no database table to set. We save these values in below variables
 
public $version = "0.1.0";
public $name = "Page";
public $db_table = "pages";

 

A model can validate field data before we save. All validation role saved in below variable:
 
protected $model_validation = Array();

 

Model class can contain call back functions to execute on diffident event

 

 

Example of a Model: 
 
class pageModel extends appRain_Base_Model
{
    public $version = "0.1.0";
    public $name = "Page";
    public $db_table = "pages"// Assign false if there is not table to set. 
    public $model_validation = Array();
 
    public function _beforeSave($Model){
    }   
 
    public function _afterSave($Model){
    }
 
    public function _onValidationSuccess($Model){
    }   
 
    public function _onValidationFailed($Model){
    }
}