1、yii 登录
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>登录页面</title>
</head>
<body>
<center>
<input name="_csrf" type="hidden" id="_csrf" value="<?= Yii::$app->request->csrfToken ?>">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="nname" id="na"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd" id="pa"></td>
</tr>
<tr>
<td></td>
<td><input type="button" value="登录" id="de"></td>
</tr>
</table>
<ul id="lis">
</ul>
</center>
</body>
</html>
<script src="jquery-1.9.1.min.js"></script>
<script>
$(function(){
$("#de").click(function(){
var name=$("#na").val();
var pwd=$("#pa").val();
$.ajax({
type:"GET",
//dataType:"json",
url:"http://localhost/October/laravelandyii/laravel-v5.1.11/public/index/login",
data:{name:name,pwd:pwd},
success: function(msg){
//alert(msg);
//alert( "Data Saved: " + msg );
if(msg=="ok"){
location.href="index.php?r=index/show";
}else{
alert('用户名或密码错误');
}
}
})
})
})
</script>
2、列表页
</pre><pre name="code" class="php"><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<center>
<h2>列表页面</h2>
<a href="index.php?r=index/wor">操作日志</a>
</center>
<div id="di">
</div>
</body>
</html>
<script src="jquery-1.9.1.min.js"></script>
<script>
$(function(){
$.ajax({
type:"GET",
dataType:"json",
url:"http://localhost/October/laravelandyii/laravel-v5.1.11/public/index/lists",
success: function(msg){
//alert(msg);
var trd="<table align='center' border='1'>";
trd +="<tr>";
trd +="<th>图书id</th>";
trd +="<th>图书名称</th>";
trd +="<th>图书简介</th>";
trd +="<th>图书作者</th>";
trd +="<th>图书价格</th>";
trd +="<th>操作</th>"
trd +="</tr>";
for(var i=0;i<msg.length;i++){
trd +="<tr>";
trd +="<td>"+msg[i].id+"</td>";
trd +="<td>"+msg[i].bname+"</td>";
trd +="<td>"+msg[i].bjie+"</td>";
trd +="<td>"+msg[i].bzuo+"</td>";
trd +="<td>"+msg[i].bprick+"</td>";
trd +='<td><a href="http://localhost/October/laravelandyii/laravel-v5.1.11/public/index/del?id='+msg[i]["id"]+'">删除</a></td>';
trd +="</tr>";
}
trd +="</table>";
$("#di").html(trd);
}
})
})
</script>
3、操作日志
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<center>
<h2>日志列表</h2>
<a href="index.php?r=index/show">返回</a>
<div id="ta"></div>
</center>
</body>
</html>
<script src="jquery-1.9.1.min.js"></script>
<script>
$.ajax({
type:'GET',
dataType:"json",
url:"http://localhost/October/laravelandyii/laravel-v5.1.11/public/index/work",
success:function(msg){
//alert(msg)
var str="<table border='1'>";
str +="<tr>";
str +="<th>序号</th>"
str +="<th>操作人</th>";
str +="<th>时间</th>";
str +="<th>操作内容</th>";
str +="<th>操作</th>";
str +="</tr>";
for(var i=0;i<msg.length;i++){
str +="<tr>";
str +="<td>"+msg[i]['id']+"</td>";
str +="<td>"+msg[i]['work_name']+"</td>";
str +="<td>"+msg[i]['time']+"</td>";
str +="<td>"+msg[i]['saves']+"</td>";
str +='<td><a href="http://localhost/October/laravelandyii/laravel-v5.1.11/public/index/gc?id='+msg[i].bid+'">还原</a></td>';
str +="</tr>";
}
str +="</table>";
$("#ta").html(str);
}
})
</script>
4、yii 控制器
<?php
namespace app\controllers;
use Yii;
use yii\web\Controller;
class IndexController extends Controller{
public function actionLogin(){
return $this->renderPartial('login');
}
public function actionShow(){
return $this->renderPartial('show');
}
public function actionWor(){
return $this->renderPartial('work');
}
}
?>
5、laravel 控制器
<?php
namespace App\Http\Controllers;
use DB;
use Log;
use App\User;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Controllers\Session;
class IndexController extends Controller{
public function login(Request $request){
$name=$request->input('name');
$pwd=$request->input('pwd');
$re=DB::table('buser')->where("username",$name)->first();
if($re){
$request->session()->put('name',$name);
echo "ok";
}else{
echo "no";
}
}
public function lists(){
$data=DB::select("select * from bbook where status=0");
//print_r($data);die;
exit(json_encode($data));
}
public function del(Request $request){
$username=session()->get('name');
//echo $username;die;
$id=$request->input('id');
//echo $id;
$de=DB::table('bbook')->where('id',$id)->update(['status'=>1]);
if($de){
$time=date("Y-m-d H:i:s");
$saves=$username."删除了id为"."$id"."的图书";
$arr=array('work_name'=>$username,'time'=>$time,'saves'=>$saves,'bid'=>$id);
$this->works($arr);
$url = "http://localhost/October/laravelandyii/basic3/web/index.php?r=index/show";
echo "<script>alert('删除成功!');location.href='$url';</script>";
}else{
echo "<script>alert('删除失败!');lacation.href='$url';</script>";
}
}
public function works($arr){
DB::table('bwork')->insert($arr);
}
public function work(){
$wo=DB::table('bwork')->get();
exit(json_encode($wo));
}
public function gc(Request $request){
$username=session()->get('name');
$id=$request->input('id');
$up=DB::table('bbook')->where('id',$id)->update(['status'=>0]);
if($up){
$time=date("Y-m-d H:i:s");
$saves=$username."还原了id为".$id."的图书";
$arr=array('work_name'=>$username,'time'=>$time,'saves'=>$saves,'bid'=>$id);
$this->works($arr);
echo "<script>alert('还原图书成功!');window.history.go(-1)</script>";
}else{
echo "<script>alert('你已经还原了这本图书!');window.history.go(-1)</script>";
}
}
}
?>