【发布时间】:2020-05-08 17:45:04
【问题描述】:
我已经搜索过这个但找不到任何有用的解决方案,所以我在这里发布我的问题。我正在为我的项目使用 codeigniter MVC。我已经很好地设置了后端/管理面板,但是对于前端部分,当我尝试在 codeigniter MVC 中设置前端时出现“404 page not found”错误。
我的应用结构是:
project_name
--application
controllers
-- admin
-- front_end
-- Front_end.php
models
-- admin
-- front_end
-- Mdl_front_end.php
views
-- admin
-- front_end
-- home.php
routes.php
$route['default_controller'] = 'front_end/front_end/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;
$route['admin'] = 'admin/login';
$route['admin/gallery'] = 'admin/gallery/add';
$route['about'] = 'front_end/about';
核心/MY_Controller.php
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
}
}
?>
应用程序/控制器/front_end/Front_end.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Front_end extends MY_Controller {
public function __construct(){
parent::__construct();
}
public function index(){
$this->load->view('front_end/home');
}
}
每当我访问根 URL 时,例如:http://localhost/prject_name/ 收到“404 Page Not Found”错误。有人请指出我正确的方向吗?谢谢。
【问题讨论】:
-
尝试从默认控制器中删除索引,即
$route['default_controller'] = 'front_end/front_end'; -
路由['default_controller'] = 'front_end/front_end/index';不是一个类。应该是 route['default_controller'] = 'front_end/front_end'
-
我已经尝试过没有索引为
front_end/front_end,但效果很好。 @sauhardnc @fraggley -
$route['default_controller'] = 'front_end';然后打开http://localhost/project_name/front_end。如果您希望它仅在http://localhost/project_name上打开,则将front_end文件夹的内容直接移动到controller文件夹中。 -
你为什么没有回来看答案?
标签: php codeigniter codeigniter-3