Codeigniter 正确加载登录页面,但在提交该表单时,浏览器响应 404 Not found。我不知道真正的问题是什么。请帮忙。下面是我们的代码:
这是我的视图文件:view/login/index.php
<?= form_open(base_url().'login/index', array('id' => 'loginForm')) ?>
<div class="wrap-login">
<div id="content1">
<div id="main">
<h1>Administrator Area</h1>
<div class="full_w1">
<div class="form">
<?php if ($this->session->flashdata('message')) : ?>
<?= $this->session->flashdata('message') ?>
<?php endif; ?>
<?= form_label(lang('username'), 'username', array('data-icon' => 'u')) ?>
<?= form_input(array('name'=>'username','id'=>'username','value'=>set_value('username'),'class'=>'text','placeholder'=>'Enter Username')) ?>
<?= form_error('username') ?>
<?= form_label(lang('password'), 'password', array('data-icon' => 'p')) ?>
<?= form_input(array('type'=>'password','name'=>'password','id'=>'password','class'=>'text','placeholder'=>'Enter Password')) ?>
<?= form_error('password') ?>
<div class="sep"></div>
<?= form_submit('login', lang('login'), 'class="ok"' ) ?>
</div></div>
</div>
</div>
</div>
<?=form_close()?>
<script type="text/javascript">
$(document).ready(function()
{
$('#username').focus();
});
</script>
这是我的控制器文件:控制器/登录
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
function __construct()
{
parent::__construct();
// load model
$this->load->model('Login_model','',TRUE);
}
public function index()
{
if ($this->privilege->logged_in){
redirect('dashboard/');
}
// SET VALIDATION RULES
$valid = array(
array(
'field' => 'username',
'label' => lang('username'),
'rules' => 'trim|required|min_length[4]|max_length[15]|xss_clean'
),
array(
'field' => 'password',
'label' => lang('password'),
'rules' => 'trim|required|md5'
)
);
$this->form_validation->set_rules($valid);
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
// has the form been submitted and with valid form info (not empty values)
if($this->input->post('login'))
{echo "Hi";die;
if($this->form_validation->run())
{
$returnValue = $this->Login_model->authenticate();
if($returnValue == 'Active')
{
//echo "<pre>"; print_r($this->session->userdata('sessionkey')); echo "</pre>"; die;
$this->session->set_flashdata('message','<div class="alert success" id="msgDiv"><span class="hide" id="hideMsg">x</span>You have successfully logged-in!!</div>');
redirect('dashboard/');
}
else
{
$this->session->set_flashdata('message', '<div class="error">'.lang($returnValue).'</div>');
redirect('login/');
}
}
}
$data['title'] = "Administrator Area";
$this->load->view('common/login-header',$data);
$this->load->view('login/index');
//$this->load->view('common/footer');
}
public function logout()
{
if($this->session->sess_destroy()) {
$this->session->set_flashdata('message','<div class="alert success" id="msgDiv"><span class="hide" id="hideMsg">x</span>You have successfully logged-out!!</div>');
redirect('login/');
}
else {
redirect('dashboard/');
}
}
}