此处仅做简单描述,index.php为入口文件,system为框架代码,编辑的代码大多写到application文件夹中,其中models为模型,views为视图,controllers为控制器,config为配置文件(后续待补) php
如图为默认访问的控制器 apache
$route['default_controller'] = 'welcome';
复制代码
改成app
$route['default_controller'] = 'index/home';
复制代码
但访问 http://localhost/dashboard/ci_news/ 时报404,经发现,3.1.4版本以后不支持这样的修改,在system/core/Router.php文件下找到 _set_default_controller 方法框架
if ( ! file_exists(APPPATH.'controllers/'.$this->directory.ucfirst($class).'.php'))
{
This will trigger 404 later
return;
}
复制代码
将这一段改成codeigniter
if ( ! file_exists(APPPATH . 'controllers/' . $this->directory . ucfirst($class) . '.php'))
{
$path_arr = explode('/', trim($this->default_controller, '/'));
$class = ucfirst($path_arr[1]);
$method = isset($path_arr[2]) ? $path_arr[2]: 'index';
if (file_exists(APPPATH . 'controllers/' . $this->directory . $path_arr[0]. '/' . $class . '.php'))
{
$this->directory .= $path_arr[0]. '/';
}
}
复制代码
从新访问 http://localhost/dashboard/ci_news/this