Code Igniter: Active Record and Private Class Variables

n the Code Igniter Models documentation it details the Active Record insert, which builds the insert around your class variables, allowing you to do this:

$this->title = $_POST[‘title’];
$this->content = $_POST[‘content’];
$this->date = time();
$this->db->insert(‘entries’, $this);

However there’s a bug: it doesn’t distinguish against private class variables, leaving you with errors like this:

error, no fields in database named ‘_parent_name’ ,’_ci_scaffolding’ , and ‘_ci_scaff_table’

These private class variables (denoted by the underscore) are inherited from the base Model class, but can be stripped out by editing system/database/DB_active_rec.php function _object_to_array:

if ( ! is_object($val) AND ! is_array($val) AND substr($key, 0, 1) != ‘_’);

* DB_active_rec.php-1.5.4.patch


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout /  Ubah )

Foto Google+

You are commenting using your Google+ account. Logout /  Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout /  Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout /  Ubah )


Connecting to %s

%d blogger menyukai ini: