我已經在Phil's Sturgeon example之後創建了兩個控制器,Public_Controller和Admin_Controller在./application/libraries文件夾中。CodeIgniter自動加載特定類
我想要做的是自動加載Public_Controller和Admin_Controller specificly,所以我創建./application/config.php
function __autoload($class) {
// Autoload only Public_Controller and Admin_Controller
if (strpos($class, 'CI_') !== 0) {
$file = APPPATH . 'libraries/'. $class .'.php';
if (file_exists($file) && is_file($file)) {
@include_once($file);
}
}
}
這個我認爲這個問題在這裏面自動加載功能,我有更多的包含在庫文件夾內的文件,所以這些文件也是自動加載的,這不是我想要的。所以不是我試圖做一個小改動,第一個if語句,就像這樣:
if (in_array($class, array('Public_Controller, Admin_Controller'))) // instead of strpos
爲了目標只有這兩個類
,但這似乎並沒有工作。任何想法我可能做錯了什麼?
然後你可以這樣做:'$ this-> load-> model('Model_name');'在你想要的控制器裏面。 – Albzi