Extending the CI_DB_active_record class in codeigniter 2.0
I am writing my first program with Codeigniter, and have run into a problem. I will start with a focused description of the problem and can broaden it if I need to:
I need to write a multi-dimensional array to the DB and want to use the insert_batch function from the CI_DB_active_record class to do so. The problem is that I need to write empty values as NULL for some fields while other fields need to be empty strings. The current function wraps all values with single quotes, and I cannot find a way to write null values to the database for specified fields.
I would also like to increase the number of records per batch.
I see how to extend models, libraries, etc., but is there a way to extend the CI_DB_active_record class without modifying core classes? The minimal amount of core class modification to make this work that I have found is modifying the following lines in the DB.php file (changing the require_once file to the new file that ext开发者_C百科ends the CI_DB_active_record class and changing the CI_DB_active_record class name to the new class name):
require_once(BASEPATH.'database/DB_active_rec'.EXT);
if ( ! class_exists('CI_DB'))
{
eval('class CI_DB extends CI_DB_active_record { }');
}
Can I do better?
There is no out-of-the-box solution to do this. Your hack is a reasonable solution and if it does the job then spot on.
If you have any changes to make to the core (plenty of room for improvement in some parts of AR) then why not hop on BitBucket and help out with Reactor?
https://bitbucket.org/ellislab/codeigniter-reactor
精彩评论