形式
<?php echo validation_errors(); ?>
<?php $attributes = array('class' => 'navbar-form pull-right');
echo form_open('login/checkLogin', $attributes); ?>
<input class="span2" type="text" placeholder="Username" name="username">
<input class="span2" type="password" placeholder="Password" name="password">
<button type="submit" class="btn">Sign in</button>
</form>
控制器
<?php
class Login extends CI_Controller{
public function index(){
$this->load->view('templates/menu');
}
public function checkLogin(){
$this->form_validation->set_rules('username', 'Username', 'required|callback_verifyUser');
$this->form_validation->set_rules('password', 'Password', 'required|callback_verifyPassword');
if($this->form_validation->run() == false){
$this->load->view('pages/error');
}else{
}
}
}
?>
模型
<?php
class Login_model extends CI_Model{
public function login($name, $pass){
$this->db->select('name, pass');
$this->db->from('members');
$this->db->where('name', $name);
$this->db->where('pass', $pass);
$query = $this->db->get();
if($query->num_rows() == 1){
return true;
}else{
return false;
}
}
}
?>
结构
应用
- 控制器
- 登录.php
- 意见
- 模板
- 菜单.php
- 模板
.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !f
RewriteCond %{REQUEST_FILENAME} !d
RewriteRule .* index.php/$0 [PT,L]
我的表单位于 menu.php 中,当我推送提交时返回 404 如果需要更多信息,请询问我。