Welcome Guest, Not a member yet? Register   Sign In
Extending the native model class but having problems with the constructor
#1

[eluser]Unknown[/eluser]
Hi there,

I'm trying to extend the native model class so that it has a default method that gets all the data from the db table of the same name as the model. The problem is that any code that i put in the constructor doesn't seem to run, although i have seen examples of using the constructor in an extended native class on the web. Can anyone help?

Code:
class MY_Model extends Model {

    var $tableName;
    
    function MY_Model() {
     parent::Model();
     $modelName = explode('_model',get_class($this));        
     $this->tableName = strtolower($modelName[0]);
    }

    function getAll($sortData = array(),$fields = array()) {
                
     if(!empty($sortData)) {
     $this->db->order_by($sortData['sort_field'],$sortData['sort_direction']);            
     }
     if(!empty($fields)) {
        $this->db->select($fields);
     }
     return $this->db->get($this->tableName)->result_array();                
   }
}

thanks!!
jk.




Theme © iAndrew 2016 - Forum software by © MyBB