【发布时间】:2015-08-22 02:42:45
【问题描述】:
如果没有登录,我想在登录页面重定向用户
应用程序/钩子中的我的钩子 HK_Login.php
<?php
class HK_Login
{
private $CI;
public function checkLogin()
{
$this->CI =& get_instance();
if($this->CI->session->userdata('ID') == '' && $this->CI->uri->segment(3) != 'login' )
{
redirect($this->CI->uri->segment(1) . '/secure/login');
}
}
}
应用程序/控制器中的我的控制器 Secure.php
<?php
class Secure extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function login()
{
$this->load->view('login/index');
}
}
结果是:
Not Found
The requested URL /web/secure/login was not found on this server.
我的 .htaccess
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
我的 config.php 的一部分
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
$config['enable_hooks'] = TRUE;
自动加载
$autoload['helper'] = array('url', 'custom');
$autoload['libraries'] = array('database', 'session');
挂钩配置
$hook['post_controller_constructor'][] = array(
'class' => 'HK_Login',
'function' => 'checkLogin',
'filename' => 'HK_Login.php',
'filepath' => 'hooks'
);
这是我的 routes.php
$route['default_controller'] = 'dashboard';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
为什么给我这个错误?
在 routes.php 中添加
$route['/secure/login'] = 'secure/login';
给出同样的错误
【问题讨论】:
-
你的路线是什么样的?
-
$route['default_controller'] = 'dashboard'; $route['404_override'] = ''; $route['translate_uri_dashes'] = FALSE;
标签: php .htaccess codeigniter codeigniter-3