Php Codigniter登录可以在常规的Codeigniter上工作,但不能在Hmvc上工作
我有这个登录脚本,它在常规codeigniter上运行得非常好,但当我将它切换到hmvc codeigniter时,我开始收到404 verify not found错误。 我有三个控制器,我将在下面列出。此控制器验证登录信息Php Codigniter登录可以在常规的Codeigniter上工作,但不能在Hmvc上工作,php,codeigniter,Php,Codeigniter,我有这个登录脚本,它在常规codeigniter上运行得非常好,但当我将它切换到hmvc codeigniter时,我开始收到404 verify not found错误。 我有三个控制器,我将在下面列出。此控制器验证登录信息 class Verify extends MX_Controller { function __construct() { parent::__construct(); $this->load->model('user','',TRUE); } func
class Verify extends MX_Controller {
function __construct()
{
parent::__construct();
$this->load->model('user','',TRUE);
}
function index()
{
//This method will have the credentials validation
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
if($this->form_validation->run() == FALSE)
{
//Field validation failed. User redirected to login page
$this->load->view('login_view');
}
else
{
//Go to private area
redirect('home', 'refresh');
}
}
function check_database($password)
{
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->user->login($username, $password);
if($result)
{
$sess_array = array();
foreach($result as $row)
{
$sess_array = array(
'id' => $row->id,
'username' => $row->username
);
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
}
else
{
$this->form_validation->set_message('check_database', 'Invalid username or password');
return false;
}
}
}
这是我的登录控制器
class Login extends MX_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->helper(array('form'));
$this->load->view('login_view');
}
}
这是主控制器
session_start(); //we need to call PHP's session object to access it through CI
class Home extends MX_Controller {
function __construct()
{
parent::__construct();
}
function index()
{
if($this->session->userdata('logged_in'))
{
$session_data = $this->session->userdata('logged_in');
$data['username'] = $session_data['username'];
$this->load->view('home_view', $data);
}
else
{
//If no session, redirect to login page
redirect('login', 'refresh');
}
}
function logout()
{
$this->session->unset_userdata('logged_in');
session_destroy();
redirect('home', 'refresh');
}
}
这就是我的家
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple Login with CodeIgniter - Private Area</title>
</head>
<body>
<h1>Home</h1>
<h2>Welcome <?php echo $username; ?>!</h2>
<a href="home/logout">Logout</a>
</body>
</html>
使用CodeIgniter简单登录-私人区域
家
欢迎
这是我的登录视图
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Simple Login with CodeIgniter</title>
</head>
<body>
<h1>Simple Login with CodeIgniter</h1>
<?php echo validation_errors(); ?>
<?php echo form_open('verify'); ?>
<label for="username">Username:</label>
<input type="text" size="20" id="username" name="username"/>
<br/>
<label for="password">Password:</label>
<input type="password" size="20" id="passowrd" name="password"/>
<br/>
<input type="submit" value="Login"/>
</form>
</body>
</html>
使用CodeIgniter进行简单登录
使用CodeIgniter进行简单登录
用户名:
密码:
我不知道为什么从mvc codeigniter到hmvc会有所不同,但有些地方出了问题。非常感谢大家的帮助 所有方法的第一项检查是确保所有控制器和模型都是Ucfirst example Verify.php而不是Verify.php 如果您需要在HMVC中使用回调,那么您需要下面的代码 把这个放在图书馆里
<?php
class MY_Form_validation extends CI_Form_validation {
function run($module = '', $group = '') {
(is_object($module)) AND $this->CI = &$module;
return parent::run($group);
}
}
您是否制定了路线$route['example']=“模块/控制器/索引”
还要确保所有控制器和模块都在Ucfirst example Welcome.php而不是Welcome.phpI中。phpI根据您的建议发现了问题,以确保我的路线正确。我按照您的模式解决了问题。谢谢