国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

分類模塊的增刪改查

Original 2019-01-05 16:23:09 219
abstract:{include file="/public/head"} <body> <div class="x-nav">       <span class="layui-breadcrumb">   
{include file="/public/head"}
<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首頁</a>
        <a href="">演示</a>
        <a>
          <cite>導航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">?</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so layui-form-pane">
            <input class="layui-input" placeholder="分類名" id="title" name="title">
            <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon"></i>添加</button>
        </form>
    </div>
    <table class="layui-table layui-form">
        <thead>
        <tr>
            <th width="70">ID</th>
            <th width="200">分類名</th>
            <th width="200">管理員</th>
            <th width="200" >創(chuàng)建時間</th>
            <th width="200">操作</th>
        </thead>
        <tbody>
        {volist name="sorts" id="sort"}
        <tr>
            <td>{$sort.id}</td>
            <td>
                {$sort.title}
            </td>
            <td>{$sort.username}</td>
            <td>{$sort.time|date="Y-m-d"}</td>
            <td class="td-manage">
                <button class="layui-btn layui-btn layui-btn-xs"  onclick="x_admin_show('編輯','{:url(\'edit\')}?id={$sort.id}')"><i class="layui-icon">&#xe642;</i>編輯</button>
                <button class="layui-btn-danger layui-btn layui-btn-xs"  onclick="member_del(this,'{$sort.id}')" href="javascript:;" ><i class="layui-icon">&#xe640;</i>刪除</button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        <div>
        {$sorts|raw}
        </div>
    </div>
</div>
<style type="text/css">

</style>
<script>
    layui.use(['form'], function(){
        form = layui.form;
        form.on('submit(sreach)', function(data){
            console.log(data);
            $.post("{:url('DoAdd')}",{
                'title':$('#title').val()
            },function (data) {
                if (data.res == 1){
                    layer.msg(data.msg,{icon:1,time:1000});
                }else{
                    layer.msg(data.msg,{icon:1,time:1000});
                }
            })
            return false;
        })
    });
    /*用戶-刪除*/
    function member_del(obj,id){
        layer.confirm('確認要刪除嗎?',function(index){
            //發(fā)異步刪除數(shù)據(jù)
            $.get('{:url(\'Sort/del\')}','id='+id,function (data) {
                if (data.res == 1){
                    $(obj).parents("tr").remove();
                    layer.msg(data.msg,{icon:1,time:1000});
                }
            })

        });
    }



</script>

</body>

</html>
/******************************************************************/
<?php
/**
 * Created by PhpStorm.
 * User: NavySeals
 * Date: 2019/1/4
 * Time: 14:26
 */
namespace app\admin\controller;
use app\admin\controller\Common;
use app\admin\model\SortModel;
use think\facade\Request;
use think\facade\Session;

class Sort extends Common
{
    public function index()
    {
        //實例化模型
        $sort = new SortModel();
        $sorts = $sort->order('id','ascending')
            ->paginate(8);
        //數(shù)據(jù)賦值給模板
        $this->view->sorts = $sorts;
        //渲染分類列表
        return $this->fetch();
    }

    public function DoAdd()
    {
        //獲取提交數(shù)據(jù)
        $data = Request::param();
        $data['time']=time();
        //獲取發(fā)布管理員
        $data['username']=Session::get('username');
        $sort = new SortModel();
        if($sort->save($data)){
            return ['res'=>1,'msg'=>'發(fā)布成功'];
        }else{
            return ['res'=>0,'msg'=>'發(fā)布失敗'];
        }
    }

    public function edit()
    {
        //獲取需要修改的分類ID
        $sortId = Request::param('id');
        //通過ID獲取對應數(shù)據(jù)
        $sort = SortModel::get($sortId);
        //將查詢到的數(shù)據(jù)賦值給模板
        $this->view->sort = $sort;
        //渲染編輯界面
        return $this->fetch();
    }

    public function DoEdit()
    {
        //獲取提交數(shù)據(jù)
        $data = Request::param();
        $sort = new SortModel();
        $info = $sort->save([
            'title'=>$data['title'],
            'time'=>time(),
            'username'=>Session::get('username'),
        ],['id'=>$data['id']]);
        if($info){
            return ['res'=>1,'msg'=>'修改成功'];
        }else{
            return ['res'=>0,'msg'=>'修改失敗'];
        }
    }
public function del()
{
    //獲取需要刪除的產(chǎn)品ID
    $sortId = Request::param('id');
    //實例化模型
    $sort = new SortModel();
    //進行刪除并驗證
    if($sort->destroy($sortId)){
        return ['res'=>1,'msg'=>'刪除成功'];
        }
    }
}


Correcting teacher:天蓬老師Correction time:2019-01-05 16:29:04
Teacher's summary:頁面中不是必須的話,盡量不用轉(zhuǎn)義符,可以使用雙引號和單引號配合解決轉(zhuǎn)義問題

Release Notes

Popular Entries