我是codeigniter的新手。我正在創建一個登錄表單和過程。但是,當它發現所有與數據庫匹配的數據時,它必須重定向到一個頁面(v_home)。但它顯示此錯誤。CodeIgniter重定向方法不起作用
在此服務器上找不到請求的URL/CodeIgniter/c_home。
我的代碼是
**我的表格**
<?php echo validation_errors(); ?>
<?php echo form_open('c_verifylogin/index');
echo form_label("Username: ");
echo form_input("username");
echo "<br>";
echo form_label("Password: ");
echo form_password("password");
echo "<br>";
echo form_submit("","Login");
echo form_close();
?>
的varify類
class C_verifyLogin extends CI_Controller {
function __construct() {
parent::__construct();
//load session and connect to database
$this->load->model('m_login','login',TRUE);
$this->load->helper(array('form', 'url','html'));
$this->load->library(array('form_validation','session'));
}
function index() {
$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) {
$this->load->view('v_login');
} else {
//Go to private area
redirect(base_url('c_home'), 'refresh');
$this->load->view('v_home');
}
}
function check_database($password) {
//Field validation succeeded. Validate against database
$username = $this->input->post('username');
//query the database
$result = $this->login->login($username, $password);
if($result) {
$sess_array = array();
foreach($result as $row) {
//create the session
$sess_array = array('username' => $row->username);
//set session with value from database
$this->session->set_userdata('logged_in', $sess_array);
}
return TRUE;
} else {
//if form validate false
$this->form_validation->set_message('check_database', 'Invalid username or password');
return FALSE;
}
}
}
` <?php
function index() {
$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) {
$this->load->view('v_login');
} else {
//Go to private area
**redirect(base_url('c_home'), 'refresh');**
}
}
這裏V_home
是查看主頁和c_home
爲it.Help控制器將appriciated
什麼是要重定向到c_hone控制器功能的名稱? – goseo
索引功能。 –