ThinkPHP CURD之登录

来源:互联网 发布:馆陶县行知教育集团 编辑:程序博客网 时间:2024/06/05 22:59
<form action="/index.php?m=home&c=index&a=getUser" method="post">//跳转至控制器      用户名:<input type="text" name="txtName" size="15">      密码:<input type="password" name="txtPwd" size="15">      <input type="submit" value="登录" id="btnSend">    </form>
//此为html页面,跳转至控制器验证
public function getUser(){       $username=$_POST['txtName'];//获取表单       $password=$_POST['txtPwd'];       if(!trim($username)){          $this->error('登录失败(用户名不能为空!)');//非空验证        }         if(!trim($password)){          $this->error('登录失败(密码不能为空!)');         }           $map=array('userName'=>$username,'userPwd'=>$password,'_logic'=>'and');//创建数组       $u=D('Users')->login($map);//通过D方法找到模型层的方法      if ($u) {        $this->redirect('Index/mainUser');      }else{        $this->error('登录失败(用户名或密码错误!)');      }    }
//此为控制器代码
 public function login($map){          return $this->_db->where($map)->find();//通过ThinkPHP自带的查询语句来验证用户;    }
此为模型层代码


   
 
原创粉丝点击