爲了解決這個問題,通常大多數人的「_model」後綴添加到模型中的類名
我認爲這是更好的後綴添加到控制器代替,因爲他們幾乎從來不會被類引用代碼中的名稱。
首先我們需要擴展Router類。
創建這個文件:「應用程序/庫/ MY_Router.php」
class MY_Router extends CI_Router {
var $suffix = '_controller';
function __construct() {
parent::CI_Router();
}
function set_class($class) {
$this->class = $class . $this->suffix;
}
function controller_name() {
if (strstr($this->class, $this->suffix)) {
return str_replace($this->suffix, '', $this->class);
}
else {
return $this->class;
}
}
}
現在編輯「系統/笨/ CodeIgniter.php」
行153:
if (! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->controller_name().EXT))
線158:
include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->controller_name().EXT);
接下來,編輯:「系統/庫/ Profiler.php」,行323:
$output .= "
<div style="color:#995300;font-weight:normal;padding:4px 0 4px 0">".$this->CI->router->controller_name()."/".$this->CI->router->fetch_method()."</div>";
Source
這就是爲什麼你應該嘗試找到一個框架,它可以讓你使用PHP5.3 [namespaces](http://php.net/manual/en/language.namespaces.php)。就像我討厭這個框架一樣,FuelPHP可能是你合乎邏輯的一步。它非常新的CI叉。那當然,如果你能控制使用哪個框架,或者你處於可能的階段。如果不是,請在下一個項目中繼續考慮。 – 2012-03-24 09:23:13
不知道你從FuelPHP得到的想法是CI的一個分支。它不是,從零開始建立,與CI沒有任何共同之處,並且不兼容。 – WanWizard 2013-03-26 12:15:30