路由
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. JVM 问题分析思路

    1. 前言 工作中有可能遇到 java.lang.OutOfMemoryError: Java heap space 内存溢出异常, 本文提供一些内存溢出的分析及解决问题的思路. 常见异常如下: 20 ...

  2. Tomcat下 session 持久化问题(重启服务器session 仍然存在)

    感谢大佬:https://www.iteye.com/blog/xiaolongfeixiang-560800 关于在线人数统计,大都使用SessionListener监听器实现. SessionLi ...

  3. 什么是Segue

    Storyboard上每一根用来界面跳转的线,都是一个UIStoryboardSegue对象(简称Segue) Segue的属性 每一个Segue对象,都有3个属性唯一标识@property (non ...

  4. ValueStack与ContentMap (ActionContext.getContext().getValueStack().set())

    在方法 <action name="zilei" class="dtreeAction" method="zilei">   & ...

  5. hibernate中的映射文件xxx.hbm.xml详解总结

    转自 http://blog.csdn.net/a9529lty/article/details/6454924 一.hibernate映射文件的作用: Hibernate映射文件是Hibernate ...

  6. Hibernate与JDBC事务整合

    一般大家都会使用Spring声明型事务 transactionAttributes 为 PROPAGATION_REQUIRED Hibernate 使用 HibernateTransactionMa ...

  7. Ansible自动化运维工具及其常用模块

    Ansible自动化运维工具及其常用模块 目录 Ansible自动化运维工具及其常用模块 一.Ansible简介 1. Ansible概述 2. Ansible作用 3. Ansible的工作模块 4 ...

  8. jenkins插件Publish Over SSH因安全问题下架

    最近用docker新搭建了一个jenkins,安装插件的时候发现publish over ssh找不到了,官方给出的解释是存在安全隐患于2022.01.12暂停分发,官方解释如下:https://ww ...

  9. 07.python语法入门--流程控制

    分支结构 什么是分支结构 为什么要用分支结构 如何使用分支结构 if语法 if应用案例 循环结构 什么是循环结构 为什么要用循环结构 如何使用循环结构 while循环语法 while循环应用案例 fo ...

  10. Note -「多项式」基础模板(FFT/NTT/多模 NTT)光速入门

      进阶篇戳这里. 目录 何为「多项式」 基本概念 系数表示法 & 点值表示法 傅里叶(Fourier)变换 概述 前置知识 - 复数 单位根 快速傅里叶正变换(FFT) 快速傅里叶逆变换(I ...