CodeIgniter Hooks为活动记录库 [英] CodeIgniter Hooks for Active Record library
问题描述
我需要一些帮助来理解CodeIgniter的钩子逻辑,使代码适应我的需要。
页面: http://ellislab.com/codeigniter/user-guide/general/hooks.html
事实上,我不得不修改MySQL的数据库驱动程序:
function _from_tables
{
$ tables = array($ tables))
{
if(!is_array
}
return'('.implode(',',$ tables)。')';
}
:
function _from_tables($ tables)
{
if(!is_array($ tables))
{
$ tables = array表);
}
return implode(',',$ tables);
}
我使这个mod使用UNION查询使用活动记录库。 >
有人可以帮我做一个钩子,以防止我更新核心系统时我的修改被覆盖?
您可以在 CodeIgniter Wiki - 扩展数据库驱动程序
解决方案有3个简单的步骤:
1)通过创建文件MY_Loader.php来扩展你的loader类。将它
放入你的应用程序路径中的库目录(或者如果你是
使用CI 2.xx然后把它放到application\core \ path):
2)将以下函数添加到您的MY_Loader类中:
3)创建数据库驱动程序扩展类,名为
MY_DB_mysql_driver。 php(或用mysql部分替换你使用的
驱动程序 - 对于下面代码中的类名也是这样)。
将此文件也放在应用程序库目录中:
您的自定义数据库驱动程序将类似于
class MY_DB_mysql_driver extends CI_DB_mysql_driver {
function __construct($ params){
parent :: __ construct );
log_message('debug','Extended DB driver class instantiated!');
}
function _from_tables($ tables)
{
if(!is_array($ tables))
{
$ tables = array ($ tables);
}
return implode(',',$ tables);
}
}
I need some help to understand CodeIgniter's hook logic to adapt the code to my needs.
The page : http://ellislab.com/codeigniter/user-guide/general/hooks.html
In fact, I had to modify the database driver for MySQL from this :
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return '('.implode(', ', $tables).')';
}
to this :
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return implode(', ', $tables);
}
I made this mod to use UNION queries using Active Record library.
Can someone help me to make a hook in order to prevent my modification from being overwritten when I update the core system ?
Thanks in advance !
You can find the instructions for extending the db drivers on the CodeIgniter Wiki - Extending Database Drivers
The solution comes in 3 simple steps:
1) Extend your loader class by creating the file MY_Loader.php. Put it into your libraries directory in the application path (or if you are using CI 2.x.x then put it into application\core\ path):
2) Add the following function to your MY_Loader class:
3) Create your Database driver extension class, that you name MY_DB_mysql_driver.php (or substitute the mysql part for whatever driver you use - do that also for the classnames in the code below!). Put this file also in your applications libraries directory:
Your custom DB driver will look like this
class MY_DB_mysql_driver extends CI_DB_mysql_driver {
function __construct($params){
parent::__construct($params);
log_message('debug', 'Extended DB driver class instantiated!');
}
function _from_tables($tables)
{
if ( ! is_array($tables))
{
$tables = array($tables);
}
return implode(', ', $tables);
}
}
这篇关于CodeIgniter Hooks为活动记录库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!