我嘗試在Codeigniter中創建一個簡單的用戶登錄,但我無法通過Post獲取表單數據。CodeIgniter無法發佈數據
看Simple代碼 控制器
class User extends CI_Controller{
function login(){
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'username', 'required');
$this->form_validation->set_rules('password', 'password', 'required');
$this->form_validation->set_error_delimiters('<em>','</em>');
if($this->input->post('weiter')){
if($this->form_validation->run()){
echo "okay";
}
}else{
$this->load->view("templates/header");
$this->load->view("user/login");
$this->load->view("templates/footer");
}
}
}
路由配置
$route['user/login'] = 'user/login';
形式:
<?php echo form_open("user/login");?>
<table>
<tr>
<td><label for="username">Username</label></td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td><label for="password">Passwort</label></td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td><input type="submit" name="weiter"></td>
<td></td>
</tr>
</table>
當我用Chrome瀏覽器中的開發工具看時,它看到的是Post,但返回狀態是404,爲什麼我可以幫助某人?
這是無關緊要的(你可以從你的項目中刪除它)。如果這個頁面的網址是http://example.com/user/login,你可以把<?php echo form_open(); ?> –