新聞中心
本文主要記錄一些自己在瀏覽CI代碼時(shí)候的一些體會(huì), 并不分析CI的使用。

一 、 首先的一點(diǎn)就是, 已加載類在codeigniter, controller, model中的通用, 這使得CI的controller和model功能豐富。
體現(xiàn)在Controller中的構(gòu)造函數(shù)中:
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class); //將加載過(guò)的載入
}
$this->load =& load_class(\'Loader\', \'core\');
$this->load->initialize(); // 加載autoload配置的庫(kù)類
體現(xiàn)在model中:
function __get($key)
{
$CI =& get_instance();
return $CI->$key;
}
方法中
通過(guò)這樣的操作, 是的CI的controller, model 功能豐富。
2、 CI允許擴(kuò)展核心系統(tǒng)類:
在/system/core/common 中:
load_class 中有如下幾行:
foreach (array(APPPATH, BASEPATH) as $path) { if (file_exists($path.$directory.\'/\'.$class.\'.php\')) { $name = $prefix.$class; if (class_exists($name) === FALSE) { require($path.$directory.\'/\'.$class.\'.php\'); } break; } } // Is the request a class extension? If so we load it too if (file_exists(APPPATH.$directory.\'/\'.config_item(\'subclass_prefix\').$class.\'.php\')) { $name = config_item(\'subclass_prefix\').$class; if (class_exists($name) === FALSE) { require(APPPATH.$directory.\'/\'.config_item(\'subclass_prefix\').$class.\'.php\'); } }
對(duì)于Controller的重寫體現(xiàn)在(system/core/codeingiter):
require BASEPATH.\'core/Controller.php\';
function &get_instance()
{
return CI_Controller::get_instance();
}
if (file_exists(APPPATH.\'core/\'.$CFG->config[\'subclass_prefix\'].\'Controller.php\'))
{
require APPPATH.\'core/\'.$CFG->config[\'subclass_prefix\'].\'Controller.php\';
}
這可以滿足自己的業(yè)務(wù)邏輯的修改, 例如可以在自己擴(kuò)展出來(lái)的controller中加一些權(quán)限控制的操作等等。
3、 Loader類也被controller加載了(依附在controller上的model也享受利益), 通過(guò)這個(gè)類,可以實(shí)現(xiàn)各種功能庫(kù)的加載
4、 可以掛載多個(gè)系統(tǒng)
根據(jù)業(yè)務(wù)需求可能需要開(kāi)發(fā)多個(gè)系統(tǒng), 可以在index.php , 根據(jù)業(yè)務(wù)類型, 修改index.php
$applocation_folder參數(shù)
例如: 可以在配置虛擬主機(jī)的時(shí)候, 設(shè)置service_name 等等 當(dāng)然這只是一種思路
(待續(xù))
對(duì)CI的common文件比較糾結(jié)的就是, 在整個(gè)框架代碼中, 突然出來(lái)一個(gè)這個(gè)理的方法還是有點(diǎn)讓人不知所措, 覺(jué)得應(yīng)該在方法的前面加上一個(gè)common_之類的標(biāo)記, 然后自己也可以在里面創(chuàng)建一個(gè)自己的同類文件, 在方法的前面標(biāo)記上my_,, 可能會(huì)更加清晰一些
分享名稱:CI框架代碼體會(huì)
分享路徑:http://www.dlmjj.cn/article/choeog.html


咨詢
建站咨詢
