CodeIgniter Forums
My patch to make DataMapper work with CI 2.0.3 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: My patch to make DataMapper work with CI 2.0.3 (/thread-45758.html)



My patch to make DataMapper work with CI 2.0.3 - El Forum - 10-04-2011

[eluser]mikelexp[/eluser]
This is my patch to be able to use DataMapper with CI 2.0.3. It's really basic but it seems to be working fine.

First, edit system/database/DB.php. Lines 127 and 128 should look like this:

Code:
require_once(APPPATH.'core/MY_DB_active_record.php'); // new line
eval('class CI_DB extends MY_DB_active_record { }'); // modified line

Finally, save this code as <application_folder>/core/MY_DB_active_record.php:

Code:
&lt;?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class MY_DB_active_record extends CI_DB_active_record {

public function _max_min_avg_sum($select = '', $alias = '', $type = 'MAX') {
  return parent::_max_min_avg_sum($select, $alias, $type);
}

public function _create_alias_from_table($item) {
  return parent::_create_alias_from_table($item);
}

public function _where($key, $value = NULL, $type = 'AND ', $escape = NULL) {
  return parent::_where($key, $value, $type, $escape);
}

public function _where_in($key = NULL, $values = NULL, $not = FALSE, $type = 'AND ') {
  return parent::_where_in($key, $values, $not, $type);
}

public function _like($field, $match = '', $type = 'AND ', $side = 'both', $not = '') {
  return parent::_like($field, $match, $type, $side, $not);
}

public function _having($key, $value = '', $type = 'AND ', $escape = TRUE) {
  return parent::_having($key, $value, $type, $escape);
}

public function _track_aliases($table) {
  return parent::_track_aliases($table);
}

public function _compile_select($select_override = FALSE) {
  return parent::_compile_select($select_override);
}

public function _merge_cache() {
  return parent::_merge_cache();
}

public function _reset_run($ar_reset_items) {
  return parent::_reset_run($ar_reset_items);
}

public function _reset_select() {
  return parent::_reset_select();
}

public function _reset_write() {
  return parent::_reset_write();
}

}

That's it. I'm extending CI_DB_active_record to make its protected methods public so DataMapper can access them. But I'm no CI guru so maybe more experienced coders will find potential problems.