?? ???? ???? Thinkphp ??: 1. index/login ??? ? login.html ???? ????. 2. ? ??? ????? ????. 3. "??? ?? ??(){...}? ?? ??? ?????. " ?? ??; 4. "dispatch_jump.tpl" ??? ???. 5. "config.php"?? ?? ??? ?????.

? ????? ?? ??: Windows 7 ???, ThinkPHP ?? 5, Dell G3 ???.
ThinkPHP5 ??? ??
??? ?? ??
?? ??? ?? ? ?? ??? ???? ??? ? ????
1 index/login
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登陸</title>
</head>
<body>
<!--{:url('check')} :提交到本頁面的控制器下的check方法-->
<form action="{:url('check')}" method="post">
<p>
賬號:<input type="text" name="username" id="username">
</p>
<P>
密碼:<input type="text" name="password" id="password">
</P>
<p>
<input type="submit" value="提交">
<input type="reset" value="重置">
</p>
</form>
</body>
</html>
? ? login.html ???? ????. ??? ??? ????? ?? ??? ?? ??
namespace app\index\controller;
use think\Controller;
//繼承Controller
class Login extends Controller
{
public function index(){
return view();
}
// 判斷登陸成功失敗的邏輯
public function check(){
$user=$_POST['username'];
$pwd=$_POST['password'];
if($user=='admin' && $pwd=='123'){
// 如果成功則跳到index/index頁面
$this->success('登陸成功',url('/index/index'));
}else{
$this->error('登陸失敗');
}
}
}
System
/**
* 操作成功跳轉(zhuǎn)的快捷方法
* @access protected
* @param mixed $msg 提示信息
* @param string $url 跳轉(zhuǎn)的 URL 地址
* @param mixed $data 返回的數(shù)據(jù)
* @param int $wait 跳轉(zhuǎn)等待時間
* @param array $header 發(fā)送的 Header 信息
* @return void
* @throws HttpResponseException
*/
protected function success($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
{}
???? ??? ??? ??: ??() ???? ?? ?? ?????? ?? ??, ?? ?? /index/index? ?????. ??? ??( ) ????? ?? ?????? ????

?? ?????? ?????. ???? ???? ???? ?????? ??? ?? ??? ???? ?? ? ???? ? ??? ?????? ???? ???
1. ??? ?????? ?? config.php? ???. ?? ? ?? ??? ? ? ????
// 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', //成功跳轉(zhuǎn)的界面
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl', //失敗跳轉(zhuǎn)的界面
?? ??? ?? ?? ?? ??? ??? ?????? dispatch_jump.tpl?? ? ? ????. thinkphptpldispatch_jump.tpl ??? ?? ?? ????
? ?? ??? ??? ?????. ??? ?? ??? ???????
<!--根據(jù)code來判斷顯示成功還是失敗,1代表成功,0代表失敗-->
<?php switch ($code) {?>
<?php case 1:?>
<h1>:)</h1>
<!--這行代碼是我自己在static下添加的一張成功的笑臉圖片,路徑是根據(jù)入口文件的位置來定義圖片的位置,入口文件和static是同一級目錄-->
<img src="/static/imghw/default1.png" data-src="/static/xiao.jpg" class="lazy" style="max-width:90%" height="100px" alt="thinkphp?? ?? ???? ???? ??" >
<p><?php echo(strip_tags($msg));?></p>
<?php break;?>
<?php case 0:?>
<h1>:(</h1>
<!--這行代碼是我自己在static下添加的一張失敗的哭臉圖片,路徑是根據(jù)入口文件的位置來定義圖片的位置,入口文件和static是同一級目錄-->
<img src="/static/imghw/default1.png" data-src="/static/ku.jpg" class="lazy" style="max-width:90%" height="100px" alt="thinkphp?? ?? ???? ???? ??" >
<p><?php echo(strip_tags($msg));?></p>
<?php break;?>
<?php } ?>
2. ?? ??? ???? ??? ?????? ?? ? ?? ? ??? ????. thinkphptpl ????, ??? ??.tpl ? ??? ?? tpl ??, config.php
//原來指定的路徑
// 默認(rèn)跳轉(zhuǎn)頁面對應(yīng)的模板文件
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'dispatch_jump.tpl'
//修改為自定義的文件路徑
'dispatch_success_tmpl' => THINK_PATH . 'tpl' . DS . 'success.tpl',
'dispatch_error_tmpl' => THINK_PATH . 'tpl' . DS . 'error.tpl'
bootstrap?? ?? ??? ??????. ???, ????? ? ?, ??? ??? ??????
?? ??: "thinkPHP ??? ????"
? ??? thinkphp?? ?? ???? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!