codeigniter-base-model
My CodeIgniter Base Model is an extended CI_Model class to use in your CodeIgniter applications. It provides a full CRUD base to make developing database interactions easier and quicker, as well as an event-based observer system, in-model data validation, intelligent table name guessing and soft delete.
Synopsis
$this->load->model('post_model', 'post');
$this->post->get_all();
$this->post->get(1);
$this->post->get_by('title', 'Pigs CAN Fly!');
$this->post->get_many_by('status', 'open');
$this->post->insert(array(
'status' => 'open',
'title' => "I'm too sexy for my shirt"
));
$this->post->update(1, array( 'status' => 'closed' ));
$this->post->delete(1);
Installation/Usage
Download and drag the MY_Model.php file into your application/core folder. CodeIgniter will load and initialise this class automatically for you.
Extend your model classes from MY_Model and all the functionality will be baked in automatically.
Naming Conventions
This class will try to guess the name of the table to use, by finding the plural of the class name.
For instance:
class Post_model extends MY_Model { }
...will guess a table name of posts. It also works with _m:
class Book_m extends MY_Model { }
...will guess books.
If you need to set it to something else, you can declare the $_table instance variable and set it to the table name:
class Post_model extends MY_Model
{
public $_table = 'blogposts';
}