<?php namespace HomeController; use ThinkController; class LoginController extends Controller{ public function login(){ //显示页面,实现登录 if ( empty ( $_POST )){ $this ->show(); } else { //处理登录逻辑 $uid = $_POST [ "uid" ]; $pwd = $_POST [ "pwd" ]; $db = D( "Users" ); $arr = $db ->find( $uid ); if ( $arr [ "pwd" ]== $pwd &&! empty ( $pwd )){ $url = U( "mains" ); //不同控制器下的方法要写控制器名 //不在不同模块下要加上模块名 $this ->success( "登录成功!" , $url ); } else { $this ->error( "登陆失败!" ); //默认跳转到上一个界面 } } } public function mains(){ } } |
|
<html> <head> </head> <body> <form action= "" method= "post" > <div>用户名:<input type= "text" name= "uid" /></div> <div>密码:<input type= "password" name= "pwd" /></div> <input type= "submit" value= "登录" /> </form> </body> </html> |