Welcome Guest, Not a member yet? Register   Sign In

Can anyone explain how the lib 'MY_MODEL' works that's floating around the forums, net?

I want a CRUD script i can use all the time without repeating myself, is this what it is?

Yes, that's what it is. But it's just for database crudding, not actual controller crudding liek GroceryCRUD.

For some nice MY_Models look at

This https://github.com/jamierumbelow/codeigniter-base-model is the one I have, so my understanding is that;

I can use
class Test extends My_Model {
      public function myMethod {
           // Then be able to use like $this->db->get(); as per jamies My_Model is that correct?
           // does it not use the core CI_Model/$this->db->get() as per the manual?

No, it would actually be:

class Things extends MY_Model {
    // automatically set to plural form of your model name...in this case, 'thingss'

    var $_table = 'things';

    public function __construct() {


Then, to use it:



Gracias (Thanks) your a legend just what I needed thank you!

For Jamie's MY_Model, you are supposed to name your model with the singular version of the table name, and the table name should be plural. That way, you generally don't have to explicitly set the $_table property.

Also, there is no need to call parent::__construct or even have a __construct() method at all in most cases. So your entire 'Things' model could be just a one liner if the MY_Model methods cover your needs:

<?php class Thing extends MY_Model {}

...and then to use it:


Theme © iAndrew 2016 - Forum software by © MyBB