I’m working on a project (using codeigniter) where I use a lot of Active record .
The problem i’m facing is the following :
I receive an array of data and i have to fill few tables by using :
$this->db->insert('db_name', $data);
Now sometime $data contains elements not available inside the table so instead i have to do something like :
unset($data['action']);
unset($data['date']);
Before inserting or I just build another array that contains the exact same element of a specific table .
$arr = array( 'x' => $data['x'])
I already used Kohana before and i know when you insert using the ORM it just ignores elements not available in a specific table .
Is there something like that in Codeigniter ?
PS) Without using any external library
CI ActiveRecord is not an ORM. If you want to use an ORM with codeignter, your only option is to use a third-party library: http://datamapper.wanwizard.eu/
You can always loop through the array before sending it to the db and unset data that doesn’t contain anything (if in fact the delineator is an empty element):
Otherwise, you could create
switchspaghetti to unset the elements based on the db and the page sending the data: