Codeigniter MY MODEL

Base model (MY_Model) for the Codeigniter framework.

VERY IMPORTANT NOTE: MY_Model DOESN’T REPLACE THE QUERY BUILDER. IF YOU HAVE A VERY COMPLEX QUERY, DO NOT ASK MY_Model TO DO IT FOR YOU

Installation/Usage

Download and drag the MY_Model.php file into your application/core directory. CodeIgniter will load and initialise this class automatically.

Extend your model classes from MY_Model and all the functionality will be baked in automatically.

original source from github https://github.com/avenirer/CodeIgniter-MY_Model

class User_model extends MY_Model
{
public $table = 'users'; // you MUST mention the table name
public $primary_key = 'id'; // you MUST mention the primary key
public $fillable = array(); // If you want, you can set an array with the fields that can be filled by insert/update
public $protected = array(); // ...Or you can set an array with the fields that cannot be filled by insert/update
public function __construct()
{
parent::__construct();
}
}

Synopsis

class User_model extends MY_Model { }

$this->load->model('user_model');

$this->user_model->get(1)

$this->user_model->get_all();

$this->user_model->where('username','kushansh')->get();

$this->user_model->insert(array('username' => 'kushansh','email' => 'kushansh@gmail.com'));

$this->user_model->update(array('status' => '0'), 1);

$this->user_model->delete(1);

0 0 vote
Article Rating

by kushan


Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments