专业5 登录+采集+分页+静态化+搜索+预处理登录+伪静态+删除+修改+下拉分页+退出登录
、、、、、登录页面
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>new login登录页面</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<form action="newlogins.php" method="post" style="width: 300px;">
<div class="form-group">
<label for="name">账号</label>
<input type="text" class="form-control" placeholder="请输入账号" name="name">
</div>
<div class="form-group">
<label for="name">密码</label>
<input type="password" class="form-control" name="pwd" placeholder="请输入密码">
</div>
<input type="submit" value="立即登录">
</form>
</body>
</html>
<?php
//接受前端值
$name=$_POST['name'];
$password=$_POST['pwd'];
if (empty($name)){
echo '登录账号不可以为空';
header('refresh:2,url=newlogin.php');
die;
}
if (empty($password)){
echo '登录密码不可以为空';
header('refresh:2,url=newlogin.php');
die;
}
/////链接数据库
$link=new PDO('mysql:host=127.0.0.1;charset=utf8;dbname=day4','root','root');
$sql='select * from testlogin where name=? and password= ?';
// 进行预处理准备
$PDOStatement=$link->prepare($sql);
//绑定预处理
$PDOStatement->bindParam(1,$name);
$PDOStatement->bindParam(2,$password);
//绑定预处理
$res=$PDOStatement->execute();
$data=$PDOStatement->fetch(PDO::FETCH_ASSOC);
if (!empty($data)){
session_start();
$_SESSION['name']=$data->name;
echo '登录成功';
header('refresh:2,url=http://www.yanbing.com/list/new');
}else{
echo '登录失败';
header('refresh:2,url=newlogin.php');
}
//8.5new采集路由//展示列表
Route::get('/list/new','newsController@listNew');
//非伪静态
Route::get('/list/newone/{id}','newsController@listoNewone');
//数据伪静态
Route::get('/list_{id}.html','newsController@listoNewone');
//new删除
Route::get('/list/del/{id}','newsController@del');
//修改展示页面
Route::get('/list/updatalist/{id}','newsController@updatalist');
//修改页面
Route::post('/list/updata','newsController@updata');
...................................................................控制器页面
<?php
namespace App\Http\Controllers;
use App\models\newModel;
use Illuminate\Http\Request;
use QL\QueryList;
class newsController extends Controller
{
//new login前台页面
public function getnew()
{
//采集的网址
$url = "https://m.thepaper.cn/baijiahao_13870179";
$content = file_get_contents($url);
//采集的范围
$range = "#container";
//采集的规则
$rules = [
'title' => ['#title', 'text'],
// 'text'=>['.contentFont','text'],
'time' => ['span', 'text'],
'img' => ['img', 'src']
];
//图片本地化
$data = QueryList::html($content)->rules($rules)
->range($range)
->queryData();
// foreach ($data as $k=>$v){
// $imgs=$v['img'];
//
// }
// die;
$res = newModel::insertnew($data);
// var_dump($res);
if ($res) {
echo '采集成功';
header('refresh:2,url=/list/new');
} else {
echo '采集失败';
header('refresh:2,url=/list/new');
}
}
//列表展示
public function listNew(Request $request )
{
$word=$request->input('word');
$data = newModel::listnew($word);
return view('cj.listnew', compact('data','word'));
}
//标题小说详情静态化处理
public function listoNewone($id)
{
$data = newModel::listoNewone($id);
return view('cj.listnewone', compact('data'));
}
//删除
public function del($id){
$res=newModel::del($id);
if ($res){
echo "<font color='red'>删除成功</font>";
header('refresh:2,url=/list/new');
}else{
echo "<font color='red'>删除失败</font>";
header('refresh:2,url=/list/new');
}
}
//修改展示页面
public function updatalist($id){
$data=newModel::updatalist($id);
return view('cj.updatalist',compact('data'));
}
//修改页面
public function updata(Request $request){
$params=$request->except('_token');
$path='/'.$request->new_img;
$params['new_img']=$path;
$res=newModel::updata($params);
if ($res){
echo "<font color='red'>修改成功</font>";
header('refresh:2,url=/list/new');
}else{
echo "<font color='red'>修改失败</font>";
header('refresh:2,url=/list/new');
}
}
}
..............................................................模型页面
<?php
namespace App\models;
use http\Env\Request;
use Illuminate\Database\Eloquent\Model;
//引入软删除
use Illuminate\Database\Eloquent\SoftDeletes;
class newModel extends Model
{
use SoftDeletes; //使用软删除
protected $table='bdnew';
public $primaryKey='id';
public $timestamps=false;
public static function insertnew($params){
return self::insert($params);
}
//展示
public static function listnew($word){
return self::where('title','like',"%$word%")
->paginate(3);
}
//标题小说详情静态化处理
public static function listoNewone($id){
return self::find($id);
}
//删除
public static function del($id){
return self::find($id)->delete();
}
//修改展示页面
public static function updatalist($id){
return self::find($id);
}
//修改页面
public static function updata( $params){
$obj=self::find($params['updata_id']);
$obj->title=$params['title'];
$obj->time=$params['time'];
$obj->img=$params['new_img'];
return $obj->save();
}
}
...................................................................数据展示页面
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>列表展示</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<p>
</p>
<p>
<a href="http://127.0.0.1/1906A/week/blog/public/pdo/newlogin.php " style="color: red">退出登录</a>
</p>
<form action="/list/new" method="get">
<p>
<input type="text" class="form-control" style="width: 200px" placeholder="请输入关键字进行查询" name="word">
<input type="submit" value="立即搜索" class="btn btn-info">
</p>
</form>
<table class="table">
<tr>
<td>新闻的标题</td>
<td>新闻的时间</td>
<td>新闻的封面</td>
<td>操作</td>
</tr>
@foreach($data as $k=>$v)
<tr>
<td><a href="/list_{{$v['id']}}.html">{{$v['title']}}</a></td>
<td>{{$v['time']}}</td>
<td><img src="{{$v['img']}}" alt="" width="100px" height="100px"></td>
<td>
<a href="/list/del/{{$v['id']}}">删除</a>
<a href="/list/updatalist/{{$v['id']}}">修改</a>
</td>
</tr>
@endforeach
</table>
<select name="" id="select_page" class="form-control" style="width: 200px" >
<option value="">…请选择您要跳转的页面…</option>
@for($i=1;$i<=$data->lastPage();$i++)
<option value="{{$i}}">第<span style="color: greenyellow">{{$i}}</span>页</option>
@endfor
</select>
{{$data->appends($word)->links()}}
</body>
</html>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$('#select_page').change(function () {
var pagesum= $('#select_page').val();
location.href='http://www.yanbing.com/list/new?page='+pagesum;
})
</script>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>title title详情页面</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<div class="box">
<p>
<span style="color: red"> 新闻标题</span>:{{$data['title']}}
</p>
<p>
<span style="color: red"> 新闻时间</span>:{{$data['time']}}
</p>
<p>
<span style="color: red"> 新闻封面</span>:<img src="{{$data['title']}}" alt="无法显示" width="100" height="100" >
</p>
</div>
</body>
</html>
<style>
.box{
margin: 0 auto;
width: 300px;
height: 300px;
border: 1px solid greenyellow;
text-align: center;
}
</style>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>修改默认值页面</title>
<link rel="stylesheet" href="http://apps.bdimg.com/libs/bootstrap/3.3.0/css/bootstrap.min.css">
</head>
<body>
<form action="/list/updata" method="post">
<div class="box">
@csrf
<p>
<span style="color: red"> 新闻标题</span>:
<textarea name="title" id="" cols="30" rows="10" >{{$data['title']}}</textarea>
</p>
<p>
<span style="color: red"> 新闻时间</span>:
<textarea name="time" id="" cols="30" rows="10" >{{$data['time']}}</textarea>
</p>
<p>
<span style="color: red">新闻封面</span>:
<img src="{{$data['img']}}" alt="无法显示" width="100" height="100" >
<input type="file" value="{{$data['img']}}" name="new_img">
</p>
{{-- 增加一个隐形的输入框,根据输入框的id进行修改 --}}
<input type="hidden" name="updata_id" value="{{$data['id']}}">
<input type="submit" value="立即修改">
</div>
</form>
</body>
</html>
<style>
.box{
margin: 0 auto;
width: 600px;
height: 8000px;
border: 1px solid greenyellow;
}
</style>