扩展在codeigniter 2.0 CI_DB_active_record类 [英] Extending the CI_DB_active_record class in codeigniter 2.0
问题描述
我写我的第一个程序与codeigniter,并遇到了一个问题。我将开始与问题的集中描述,可以扩大它,如果我需要:
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:
我需要写一个多维数组到数据库,并要使用insert_batch功能从CI_DB_active_record类的话。问题是,我需要写空值NULL对于某些字段,而其他字段需要为空字符串。目前的功能封装了单引号的所有值,我不能找到一种方法来写空值到数据库中指定的字段。
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.
我看到如何扩展模型,图书馆等,但有没有办法来扩展CI_DB_active_record类,而无需修改核心类?核心类修改的最小量,使这项工作,我发现正在修改中的db.php的文件中以下行(改变require_once文件,它扩展了CI_DB_active_record类和改变CI_DB_active_record类名新类的新文件名):
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 extends 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?
推荐答案
您可以通过扩展Loader类。具体方法如下:
You can by extending the Loader class. Here's how:
HTTP://www.simonemms .COM / code /扩展-任何─codeigniter数据库级/
这篇关于扩展在codeigniter 2.0 CI_DB_active_record类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!