这是我第一次使用 CodeIgniter,我正在尝试创建一个登录表单。每当我单击我创建的提交按钮时,它都会将我带到 404 Page Not Found 错误。
我使用以下代码在视图文件夹中创建了 view_login.php:
<?php echo form_open('user/login') ?>
<ul>
<li>
<label> username </label>
<div>
<?php echo form_input(array('id' => 'username', 'name' => 'username')); ?>
</div>
</li>
<li>
<label> password </label>
<div>
<?php echo form_password(array('id' => 'password', 'name' => 'password')); ?>
</div>
</li>
<li><?php echo validation_errors(); ?></li>
<li>
<?php echo form_submit(array('name' => 'submit'), 'login'); ?>
</li>
这是我的 user.php 控制器:
<?php
class User extends CI_controller
{
public function __construct()
{
parent::__construct();
$this->load->model('user_model');
}
public function register()
{
$this->load->library('form_validation');
if($this->form_validation->run() == FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('user/view_register');
$this->load->view('templates/footer');
}
else
{
echo 'this is being processed. thank you';
}
$this->load->view('user/view_register');
}
public function login()
{
$this->load->library('form_validation');
$data['title'] = 'Log In';
$this->load->view('user/view_login');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('user/view_login');
$this->load->view('templates/footer');
{
else
{
$user_id = $this->User_model->check_login($this->input->post('username',
$this->input->post('password');
这是我的用户模型:
class User_model extends Model {
function User_model()
{
parent::Model();
}
function check_login($username, $password)
{
$sha1_password = sha1($password);
$query_str = "SELECT user_id FROM users WHERE username = ? and password = ?";
$result = $this->db->query($query_str, array($username, $sha1_password));
if ($result->num_rows() ==1)
{
return $result->row(0)->user_id;
}
else
{
return false;
}
任何帮助将不胜感激:)