路由
use think\Route;
//展示添加表单
Route::get('create','user/user/create');
//表单提交数据
Route::post('save','user/user/save');
//展示数据
Route::get('index','user/user/index');
//删除数据
Route::get('delete/:id','user/user/delete');
//修改展示页面
Route::get('edit/:id','user/user/edit');
//修改提交数据
Route::post('update','user/user/update');

<div class="content">
<div class="header">
<h1 class="page-title">管理员新增页面</h1>
</div>
<div class="well">
<!-- add form -->
<form action="/save" method="post" id="tab" enctype="multipart/form-data">
<label>用户名:</label>
<input type="text" name="username" value="" class="input-xlarge">
<label>头像:</label>
<input type="file" name="img" value="" class="input-xlarge">
<label>邮箱:</label>
<input type="email" name="email" value="" class="input-xlarge">
<label>手机号:</label>
<input type="tel" name="tel" value="" class="input-xlarge">
<br>
<button class="btn btn-primary" type="submit">保存</button>
</form>
</div>
</div>

<?php

namespace app\user\controller;

use app\user\model\userModel;
use think\Controller;
use think\Image;
use think\Request; class User extends Controller
{
/**
* 显示资源列表
*
* @return \think\Response
*/
public function index()
{
//接受关键字
$word = input('word');
$where = [
'username' => ['like', "%$word%"]
];
$data = userModel::show($where); if (!empty($word)) {
foreach ($data as $k => $v) {
$v['username'] = str_replace($word, "<font style='color:red;'>$word</font>", $v['username']); } }
//携带参数,去视图
$this->assign('data', $data);
return view(); } /**
* 显示创建资源表单页.
*
* @return \think\Response
*/
public function create()
{
//
return view(); } /**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function save(Request $request)
{
//
$params = $request->param();
$file = $request->file('img');
//验证图片
if ($file) {
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
if ($info) {
// string(45) "20210820\0fd2d7bea8a34235624d83e914780248.gif"
$filename = DS . 'uploads' . DS . $info->getSaveName();
//缩略图
$image = \think\Image::open('.' . $filename);
$image->crop(100, 100)->save('.' . $filename);
//替换
$params['img'] = $filename;
} else {
// 上传失败获取错误信息
echo $file->getError();
}
}
$result = userModel::add($params);
if (!$result) {
$this->error('添加失败', 'save');
}
$this->success('添加成功', '/index'); } /**
* 显示指定的资源
*
* @param int $id
* @return \think\Response
*/
public function read($id)
{
//
} /**
* 显示编辑资源表单页.
*
* @param int $id
* @return \think\Response
*/
public function edit($id)
{
//
$data = userModel::edit($id); //传输数据至页面
$this->assign('data', $data);
return view(); } /**
* 保存更新的资源
*
* @param \think\Request $request
* @param int $id
* @return \think\Response
*/
public function update(Request $request, $id)
{
//
$params = $request->param();
$imgs = $request->file('imgs');
$params['imgs'] = $imgs;
$result = userModel::updateData($params); if (!$result) {
$this->error('修改失败', '/index');
}
$this->success('修改成功', '/index'); } /**
* 删除指定资源
*
* @param int $id
* @return \think\Response
*/
public function delete($id)
{
//
$result = userModel::del($id);
if (!$result) {
$this->error('删除失败', 'save');
}
$this->success('删除成功', '/index');
}
}

列表展示页面

<div class="content">
<div class="header">
<h1 class="page-title">管理员列表</h1>
</div> <div class="well">
<!-- search button -->
<form action="index" method="get" class="form-search">
<div class="row-fluid" style="text-align: left;">
<div class="pull-left span4 unstyled">
<p> 用户名:<input class="input-medium" name="word" type="text"></p>
</div>
</div>
<button type="submit" class="btn">查找</button>
<a class="btn btn-primary" href="create">新增</a>
</form>
</div>
<div class="well">
<!-- table -->
<table class="table table-bordered table-hover table-condensed">
<thead>
<tr>
<th>编号</th>
<th>用户名</th>
<th>头像</th>
<th>邮箱</th>
<th>手机号</th>
</tr>
</thead>
{foreach $data as $k=>$v}
<tbody>
<tr class="success">
<td>{$k+1}</td>
<td>{$v.username}</td>
<td><img src="{$v.img}" alt=""></td>
<td>{$v.email}</td>
<td>{$v.tel}</td>
<td>
<a href="edit/{$v.id}"> 编辑 </a>
<a href="delete/{$v.id}" onclick="return confirm('您确定要删除吗?')" > 删除 </a>
</td>
</tr>
</tbody>
</tbody>
{/foreach}
</table>
<!-- pagination -->
</div>
{$data->render()}
<!-- footer -->
<footer>
<hr>
<p> 2017 <a href="javascript:void(0);" target="_blank">ADMIN</a></p>
</footer>
</div>

//修改表单页面

<div class="content">
<div class="header">
<h1 class="page-title">管理员编辑</h1>
</div> <div class="well">
<!-- add form -->
<form action="/update" method="post" enctype="multipart/form-data">
<label>用户名:</label>
<input type="text" name="username" value="{$data.username}" class="input-xlarge">
<label>现头像:</label>
<img src="{$data.img}" alt="">
<p><span style="color: green">您可以选择重新上传的照片:</span></p>
<input type="file" name="imgs" class="input-xlarge">
<label>邮箱:</label>
<input type="email" name="email" value="{$data.email}" class="input-xlarge">
<label>手机号:</label>
<input type="tel" name="tel" value="{$data.tel}" class="input-xlarge">
<br>
<input type="hidden" name="id" value="{$data.id}">
<button class="btn btn-primary" type="submit">修改</button>
</form>
</div>
<!-- footer -->
<footer>
<hr>
<p> 2017 <a href="javascript:void(0);" target="_blank">ADMIN</a></p>
</footer>
</div>

模型页面

<?php

namespace app\user\model;

use think\Model;

class userModel extends Model
{
//
const SUM=2;
protected $table='user';
public static function add($params){
return self::create($params,true);
}
//展示数据
public static function show($where){
return self::where($where)
->paginate( self::SUM);
}
//删除数据
public static function del($id){
return self::destroy($id);
}
//修改id展示页面
public static function edit($id){
return self::find($id);
}
//执行修改
public static function updateData($params){
return self::update($params,$params['id'],true);
} }

think php 路由增删改查(搜索+关键字标红+缩略图)的更多相关文章

  1. laravel7 搜索关键字标红及手机号,身份证号隐藏

    控制器代码 public function index(Request $request) { //接受搜索关键字 $word = $request->get('name'); $start = ...

  2. Magicodes.WeiChat——ASP.NET Scaffolding生成增删改查、分页、搜索、删除确认、批量操作、批量删除等业务代码

    关于T4代码生成这块,我之前写过几篇帖子,如:<Magicodes.NET框架之路——让代码再飞一会(ASP.NET Scaffolding)>(http://www.cnblogs.co ...

  3. 一、数据库表中字段的增删改查,二、路由基础.三、有名无名分组.四、多app共存的路由分配.五、多app共存时模板冲突问题.六、创建app流程.七、路由分发.八、路由别名,九、名称空间.十、反向解析.十一、2.x新特性.十二、自定义转换器

    一.数据库表中字段的增删改查 ''' 直接在modules中对字段进行增删改查 然后在tools下点击Run manage.py Task执行makemigrations和migrate 注意在执行字 ...

  4. laravel 增删改查 数据库设置 路由设置

    laravel 框架的路由设置: url: http://www.shanzezhao.com/laraverl/my_laravel/public/index.php/indexs laravel ...

  5. 分布式搜索elasticsearch 索引文档的增删改查 入门

    1.RESTful接口使用方法 为了方便直观我们使用Head插件提供的接口进行演示,实际上内部调用的RESTful接口. RESTful接口URL的格式: http://localhost:9200/ ...

  6. Node.js、express、mongodb 入门(基于easyui datagrid增删改查)

    前言 从在本机(win8.1)环境安装相关环境到做完这个demo大概不到两周时间,刚开始只是在本机安装环境并没有敲个Demo,从周末开始断断续续的想写一个,按照惯性思维就写一个增删改查吧,一方面是体验 ...

  7. yii2-basic后台管理功能开发之二:创建CRUD增删改查

    昨天实现了后台模板的嵌套,今天我们可以试着创建CRUD模型啦 刚开始的应该都是“套用”,不再打算细说,只把关键的地方指出来. CRUD即数据库增删改查操作.可以理解为yii2为我们做了一个组件,来实现 ...

  8. laravel增删改查

    基本想法是搭建一个FormController,所有以后需要配置生成后台的controller就继承这个FormController就好了.在FormController中定义属性: class Fo ...

  9. MVC3+EF5.0 code first+Flexigrid+ajax请求+jquery dialog 增删改查

    MVC3+EF5.0 code first+Flexigrid+ajax请求+jquery dialog 增删改查 本文的目的:   1.MVC3项目简单配置EF code first生成并初始化数据 ...

随机推荐

  1. 使用Hot Chocolate和.NET 6构建GraphQL应用(6) —— 实现Query排序功能

    系列导航 使用Hot Chocolate和.NET 6构建GraphQL应用文章索引 需求 从前几篇文章可以看出,使用Hot Chocolate实现GraphQL接口是比较简单的,本篇文章我们继续查询 ...

  2. JS RegExp对象(正则表达式)

    笔记整理自:廖雪峰老师的JS教程 正则表达式语法:https://www.runoob.com/regexp/regexp-tutorial.html 目录 创建方式 方式一 方式二 简单使用 判断正 ...

  3. Android返回键

    感谢大佬:https://www.cnblogs.com/qiluboy/p/5308310.html Android中back键和home键的区别: back键 Android的程序无需刻意的去退出 ...

  4. js null和{}区别

    {}是一个不完全空的对象,因为他的原型链上还有Object呢,而null就是完全空的对象,啥也没有,原型链也没有,所以null instanceof Object === false;[]就更不用说了 ...

  5. 问题描述 ens33 不见了

    事情是这样紫的 我今天用Xshell 连接Linux 发现连接不上去百思不得其解,然后就去Linux里看 ifconfig 的配置,然后发现 ens33居然不见了,就只有lo 和 virbr()  , ...

  6. Java多线程经典案例分享

    汇总 案例一 案例二 案例三 案例四 案例五 案例六 案例七 案例一 实现一个容器,提供两个方法,add(),count() 写两个线程,线程1添加10个元素到容器中,线程2实现监控元素的个数,当个数 ...

  7. iOS组件化之-给自己的组件添加资源文件

    在 podspec 中,利用 source_files 可以指定要编译的源代码文件.可是,当我们需要把图片.音频.NIB等资源打包进 Pod 时该怎么办呢? 1.如何把资源文件打包为.bundle文件 ...

  8. 《PHP程序员面试笔试宝典》——如何进行自我介绍?

    本文摘自<PHP程序员面试笔试宝典> PHP面试技巧分享,PHP面试题,PHP宝典尽在"琉忆编程库". 自我介绍是面试中至关重要的一个步骤,很多面试官对求职者提出的第一 ...

  9. Solution -「UVA 1104」Chips Challenge

    \(\mathcal{Description}\)   Link.   在一个 \(n\times n\) 的方格图中,有一些格子已经放了零件,有一些格子可以放零件,其余格子不能放零件.求至多放多少个 ...

  10. Solution -「LOCAL」大括号树

    \(\mathcal{Description}\)   OurTeam & OurOJ.   给定一棵 \(n\) 个顶点的树,每个顶点标有字符 ( 或 ).将从 \(u\) 到 \(v\) ...