路由
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. .NET Core分析程序集最优美的方法,不用Assembly.LoadFile(),超越ReflectionOnlyLoad

    在编写.NET程序的时候,如果需要对一个程序集文件进行分析,我们可以使用Assembly.LoadFile()来加载这个程序集,然后对LoadFile()方法返回的Assembly对象进行进一步的分析 ...

  2. LCT 入门

    这是一份 \(\rm LCT\) 入门总结. 关于 \(\rm LCT\) 的复杂度这里不会提及,只会记录 \(\rm LCT\) 的基本操作和经典例题,但神奇的 \(\rm LCT\) 虽然常数巨大 ...

  3. 消息队列 - mac上安装RabbitMq (转)

    什么是RabbitMQ? RabbitMQ是由Erlang语言编写的实现了高级消息队列协议(AMQP)的开源消息代理软件(也称为面向消息的中间件).支持WIndows.Linux.MAC OS 操作系 ...

  4. 安装Varnish 及遇到的坑

      转自:http://ixdba.blog.51cto.com/2895551/682555   一.安装Varnish Varnish的安装非常简单,下面逐步介绍: 1.安装前的准备  Varni ...

  5. 清理缓存的方法 #DF

    移动应用在处理网络资源时,一般都会做离线缓存处理,其中以图片缓存最为典型,其中很流行的离线缓存框架为SDWebImage. 但是,离线缓存会占用手机存储空间,所以缓存清理功能基本成为资讯.购物.阅读类 ...

  6. 【HDU6647】Bracket Sequences on Tree(树Hash 树上Dp)

    题目链接 大意 给出一颗树,按下列方式生成一个括号序列. function dfs(int cur, int parent): print('(') for all nxt that cur is a ...

  7. Go vs Java vs C# 语法对比

    目录 1. 说明 2. 对比 2.1 关键字(keywords) 2.1.1 Go 2.1.2 Java 2.1.3 C# 2.1.4 小结 2.2 基本数据类型 2.2.1 Go 基本数据类型 2. ...

  8. VMware中Ubuntu18配置静态IP地址

    1. VMware:编辑 -> 虚拟网络编辑器 -> 更改设置 2. 取消选中:使用本地DHCP服务将IP地址分配给虚拟机,并记住子网ip 3. 点击NAT设置,记住网关地址 正常情况下V ...

  9. MXNet学习-第一个例子:训练MNIST数据集

    一个门外汉写的MXNET跑MNIST的例子,三层全连接层最后验证率是97%左右,毕竟是第一个例子,主要就是用来理解MXNet怎么使用. #导入需要的模块 import numpy as np #num ...

  10. LNMP 架构 与 部署 uwsgi 服务

    内容概要 nginx 配置文件中 location 匹配符号 LNMP 架构 uwsgi 服务部署 内容详细 一.location 使用 Nginx Location 可以控制访问网站的路径,但一个 ...