【发布时间】:2018-06-15 11:20:08
【问题描述】:
我正在使用 CodeIgniter。我在控制器和视图中有前端和后端文件夹。我尝试了服务器步骤,甚至检查了几乎所有的解决方案,但我仍然无法访问我的默认控制器
routes.php
$route['default_controller'] = 'frontend/User_control';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
/*backend*********************************/
$config['backend'] = 'backend/Access_control';
1) 我的问题是当我访问 URL http://localhost/example_ci_row/ 时
找不到 404 页面
2) 如何访问我尝试过的后端 URL http://localhost/icube_row/admin 但我得到了错误
前端用户控制
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_control extends CI_Controller {
public $current_date;
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
}
public function index(){
$this->load->view('frontend/login');
}
}
?>
后端访问控制
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Access_control extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
}
public function index(){
$this->load->view('backend/login');
}
}
?>
已编辑
当我使用以下步骤时它正在工作。我在控制器中添加了 Test.php 文件并更改了路由,然后我得到了登录页面。
Test.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Test extends CI_Controller {
public $current_date;
function __construct()
{
parent::__construct();
$this->load->library('form_validation');
$this->load->helper('form');
}
public function index(){
$this->load->view('frontend/login');
}
}
?>
routes.php
$route['default_controller'] = 'Test';
【问题讨论】:
-
可能是 .htaccess 文件丢失。请检查一次
-
@PravinVavadiya,htaccess 文件已在我的应用程序文件夹中可用。我应该在应用程序之外创建吗?
-
我认为,路线可能有问题。
-
内置的 $route['default_controller'] 不适用于子文件夹。您必须根据您的要求扩展系统路由器
-
@pradeep,你能帮我做更多吗?
标签: php codeigniter codeigniter-3