Codeigniter Datamapper - Add tablename by __construct Codeigniter Datamapper - Add tablename by __construct codeigniter codeigniter

Codeigniter Datamapper - Add tablename by __construct


Datamapper caches table definitions, controlled by the configuation property "production_cache".

If cache is enabled, the table will not be queried on every pageload, but the cached information is used.


Because the this->fields array gets filled in the parent::__construct(); And at that point the table name would still be module_universeel

Try this:

if(isset($module_table)) $this->table = $module_table;parent::__construct();


I have the solution. I add this to my datamapper model:

    public function updateTableFields(){            $this->fields = array();            $data_fields = $this->db->field_data($this->table);            foreach ($data_fields as $data_field){                $this->fields[] = $data_field->name;                $this->stored->{$data_field->name} = "";            }        }

And I added this to my constructor:

$this->updateTableFields();

And now I changed the structure succesfully. Thanks for helping me!