我已经这样做了一段时间无济于事。我在使用 codeigniter 引导登录时遇到问题。所以基本上这就是我所拥有的:
login.php - 控制器
<?php if (!defined('BASEPATH')) die();
class Login extends Main_Controller {
function __construct(){
parent::__construct();
}
public function index()
{
$this->load->view('include/header');
$this->load->view('login_view');
$this->load->view('include/footer');
}
public function process(){
// Load the model
$this->load->model('login_model');
// Validate the user can login
$result = $this->login_model->validate();
// Now we verify the result
if(! $result){
// If user did not validate, then show them login page again
$this->index();
}else{
// If user did validate,
// Send them to members area
redirect('home');
}
}
}
login_view.php - 查看
<div class="container">
<form class="form-signin" action="<?php echo base_url('login/process');?>" method="post" id="loginForm">
<h2 class="form-signin-heading"><img src="<?php echo base_url('assets/img/hms_icon.png'); ?>" />User Login</h2>
<input type="text" class="input-block-level" placeholder="Username" name="username" id="username">
<input type="password" class="input-block-level" placeholder="Password" name="password" id="password">
<button class="btn btn-large btn-primary" type="submit" name="login" id="login">Sign in</button>
<div id="report"></div>
</form>
</div> <!-- /container -->
login_model.php - 模型
<?php
Class Login_model extends CI_Model
{
function __construct(){
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'_id' => $row->userid,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>
我收到一个错误
<?php echo base_url('login/process');?>
找不到对象。我在这里缺少什么?任何帮助深表感谢。