我正在尝试设置我的codeigniter路由以为管理面板创建身份验证表单,但路由不起作用。我是CodeIgniter的初学者,我想我错过了一些东西。CodeIgniter正确设置路由
在我的服务器我把文件夹内的笨fiels在我的根目录,因此它可以这样访问:
/localhost/ci
在我的config.php设置我基本URL和删除索引页面删除的index.php:
$config['base_url'] = 'http://localhost/ci/';
$config['index_page'] = '';
而且我已编辑的.htaccess删除像CodeIgniter的文档的index.php说,所以它看起来是这样的:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
现在,我的路由配置文件看起来像这样。我把我的默认页面和路由到我的验证控制器:
$route['default_controller'] = 'auth';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['auth/login'] = "auth/login";
这是我的控制器:
类验证扩展是CI_Controller {
function __construct() {
parent::__construct();
// load libraries
}
function index() {
if (! $this->ion_auth->logged_in()) {
// redirect them to the dashboard page
redirect(base_url('auth/login'), 'refresh');
} else {
// show the dashboard page
redirect(base_url('dashboard'), 'refresh');
}
}
function login() {
$this->load->view('login');
}
当我在Web浏览器http://localhost/ci/进入它将我重定向到http://localhost/ci/auth/login,但随后出现404 Not Found错误。我错过了什么?在这一点上我有点困惑,谢谢。
不要ü有意见文件夹内的login.php页面? –
我现在在html文件中有我的视图,所以它看起来像“login.html”。那是不正确的? –
可能是多数民众赞成在。试试$ this-> load-> view('login.html');或将ur文件转换为php文件 –