パブリック関数 edit(){
if(Request::method() == 'POST'){
// print_r(Request::method());exit;
$all = Request::param();
$update = Db::table('shop_goods')- >where('id',$all['id'])->update($all);
if($update){
echo json_encode(['code' =>0,'msg'=>'修正成功']);
}else{
echo json_encode(['code'=>1,'msg'=> ;'修正失败']);
}
}else{
// print_r(Request::method());exit;
$id = Request::param('id');
$shop = Db::table('shop_goods')->where('id',$id)->find();
$cat = Db::table('shop_cat')->where('status',1)->select();
View::assign([
'shop' => $shop,
'cat' => $cat
]);
return View::fetch();
}
}
<!DOCTYPE html>
<html>
<head>
<title>< ;/タイトル>
<link rel="stylesheet" type="text/css" href="/static/layui/css/layui.css">
<script type="text/javascript" src="/static/layui/layui.js"></script>
</head>
<body style="padding:10px;">
<form class="layui-form">
<div class="layui-form-item">
<label class="layui -form-label">标题</label>
<div class="layui-input-inline">
<input type="text" class=" layui-input" name="title" value="">
</div>
</div>
<div class="layui -form-item">
<label class="layui-form-label">分类</label>
<div class="layui-input-inline ">
<select name="cat">
<option value=0 selected></option>
{volist name="cat" " id="cat_v"}
<option value="{$cat_v['id']}">{$cat_v['name']}</option>
{/volist}
</select>
</div>
</div>
<div class=" layui-form-item">
<label class="layui-form-label">原价</label>
<div class="layui-input- inline">
<input type="text" class="layui-input" name="price" value="">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">折扣</label>
<div class="layui-input-inline">
<input type="text" class="layui-input" name="discount" value="">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">库存</label>
<div class="layui-input-inline">
<input type="text" class="layui-input" name="stock" value="">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label">状态</label>
<div class="layui-input-inline">
<select name="status">
<option value="1" selected>开启</option>
<option value="2">关闭</option>
</select>
</div>
</div>
</form>
<div class="layui-form-item">
<div class="layui-input-block" >
<button class="layui-btn" onclick="save()">保存</button>
</div>
</div>
<script type="text/javascript">
layui.use(['layer','form'],function(){
form =layui.form;
layer =layui.layer;
$ =layui.jquery;
});
function save(){
$.post('/index.php/Index/add',$('form').serialize(),function(res){
if(res.code>0) {
layer.alert(res.msg,{icon:2});
}else{
layer.msg(res.msg);
setTimeout(function(){parent.window.location.reload();},1000);
}
},'json');
}
</script>
</body>
</html>
< button class="layui-btnlayui-btn-dangerlayui-btn-xs" onclick="del({$right_v.id})">删除</button>
<script type= "text/javascript">
function del(id){
layer.confirm('确定要删除吗?', {
icon:3,
btn: ['确定','取消']
}, function(){
$.post('/index.php/index/del',{' id':id},function(res){
if(res.code>0){
layer.alert(res.msg,{icon:2});
### }それ以外{### layer.msg(res.msg);
setTimeout(function(){window.location.reload();},1000);
}
},'json');
});
}
</script>