? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ThinkPHP5.0簡單實(shí)現(xiàn)登錄
本人第一次學(xué)習(xí)PHP同欠,先是學(xué)習(xí)了一下目前最流行的前端的框架Angular JS框架验残,然后就開始上手PHP的學(xué)習(xí)忱反,之前我有過學(xué)習(xí)android十個(gè)月的基礎(chǔ),再就是零零散散的學(xué)習(xí)了一下html5+css,所以打算一邊實(shí)現(xiàn)某一個(gè)功能祝拯,就打算記錄下來甚带,供自己更好的學(xué)習(xí),歡迎大家指正佳头。
首先看看前臺(tái)的代碼和效果:
再看看Script的代碼:
var app = angular.module('myApp', []);
app.controller('loginCtrl', function($scope, $http) {
$scope.login=function()
{
$http({
method: 'GET',
url: 'http://127.0.0.1/thinkphp_5.0_full/index.php/index/Index/getlogin?user='+$scope.name+'&password='+$scope.password+''
}).then(function successCallback(response) {
console.log(response.data)
location.href="first.html"
}, function errorCallback(response) {
// 請(qǐng)求失敗執(zhí)行代碼
console.log(response)
});
}
});
script的代碼里面就是使用了Angular js代碼的框架鹰贵,login的登錄函數(shù),發(fā)起了http請(qǐng)求康嘉,請(qǐng)求參數(shù)類型get,url地址就是http:服務(wù)器/thinkphp/appliaction下的目錄/.PHP文件/具體方法/參數(shù)類型
控制器里面的代碼:
public function getlogin()
{
$user=input('get.user');
$password=input('get.password');
$result=Db::query("SELECT * FROM `user_tb` WHERE USER='$user' And PASSWORD='$password'");
if(!$result)
{
return 'no';
}
else
{
echo '登陸成功';
Db::table('user_tb')->where('USER',$user)->update(['CONDITION'=>'1']);
}
}
前提是必須鏈接數(shù)據(jù)庫