2013-08-05 81 views
2

我需要一些幫助來了解CodeIgniter的掛鉤邏輯,以適應我的需要的代碼。CodeIgniter掛鉤的活動記錄庫

頁:http://ellislab.com/codeigniter/user-guide/general/hooks.html

事實上,我不得不從這個修改數據庫驅動程序爲MySQL:

function _from_tables($tables) 
{ 
    if (! is_array($tables)) 
    { 
     $tables = array($tables); 
    } 
return '('.implode(', ', $tables).')'; 
} 

這樣:

function _from_tables($tables) 
{ 
    if (! is_array($tables)) 
    { 
     $tables = array($tables); 
    } 
return implode(', ', $tables); 
} 

我做這個mod使用使用活動記錄庫的UNION查詢。

有人可以幫我做一個掛鉤,以防止在更新核心系統時我的修改被覆蓋嗎?

在此先感謝!

+2

我想你要找的定製庫,而不是掛鉤的說明。請參閱http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html - >用您自己的版本替換庫。您可以擴展數據庫驅動程序並用您自己的自定義版本替換一兩個方法。 –

回答

1

你可以找到在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:

您的自定義數據庫驅動程序擴展DB驅動程序看起來像這樣

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); 
    } 

} 
+0

我不知道我可以用幫手修改CI函數!我爲我需要的一些功能做了,但不是核心:)謝謝! 一個PHP錯誤遇到 嚴重性:8192 消息: – Marcandria

+0

我用你的方法時,遇到下列錯誤分配參照新的返回值被棄用 文件名:核心/ MY_Loader.php 行號:32 我能做什麼? – Marcandria

+0

什麼版本的PHP? – user20232359723568423357842364