修改HTML代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wanna tell her - interactive DHTML</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
</style>
<body>
<form class="form-horizontal" role="form" action="{:url('/useredit')}" method="post">
<div class="form-group">
<input type="hidden" class="form-control" id="firstname" value="{$list.id}" name = "id">
<label for="firstname" class="col-sm-2 control-label">名字</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="firstname" value="{$list.name}" name = "name">
</div>
</div>
<div class="form-group">
<label for="lastname" class="col-sm-2 control-label">姓</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="lastname" name="xing" value="{$list.xing}">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
<label>
<input type="checkbox">请记住我
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">提交信息</button>
</div>
</div>
</form>
</body>
</html>
PHP代码:
<?php
namespace app\index\controller;
use think\Controller;
use think\View;
use think\Request;
use think\Db;
class Index extends Controller
{
public function useredit(Request $Request){
//判断是否有post提交request()->isPost()
if(request()->isPost()){
$posdata = $Request->post();
var_dump($posdata);
$res = Db::table("users")->where("id",$posdata["id"])->update($posdata);
if($res){
return $this->success("OK","/userlist");
}else{
$this->success("NO","/useradd");
}
}else{
//没有post提交,调取添加页面
$id = request()->param();
$idd= $id['id'];
$data = Db::table("users")->where("id",$idd)->find();
$this->assign("list",$data);
return $this->fetch();
}
}
路由Route.php
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <[email protected]>
// +----------------------------------------------------------------------
use think\Route;
Route::get('/',"Index/abc");
Route::any('/canvas',"Index/canvas");
Route::any('/useradd',"Index/useradd");
Route::any('/userlist',"Index/datalist");
Route::get('/userdelete',"Index/userdelete");
Route::any('/useredit',"Index/useredit");
列表点击修改页面
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Wanna tell her - interactive DHTML</title>
<meta http-equiv="imagetoolbar" content="no">
<style type="text/css">
</style>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<table class="table table-condensed">
<caption>哈哈哈哈</caption>
<thead>
<tr>
<th>ID</th>
<th>名字</th>
<th>姓氏</th></tr>
</thead>
<tbody>
<!-- <volist name="data" id="a"> -->
{volist name="data" id="a"}
<tr>
<td>{$a.id}</td>
<td>{$a.name}</td>
<td>{$a.xing}</td>
<td><a style="margin-right: 10px" href="{:url('/userdelete',array('id'=>$a.id))}">删除</a><a href="{:url('/useredit',array('id'=>$a.id))}">修改</a></td>
</tr>
<!-- </volist> -->
{/volist}
</tbody>
</table>
{$data->render()}
</body>
</html>
发表评论:
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。