thinkphp5无限级分类分类的修改

更改栏目和添加差不多,主要是更新数据库数据操作,这里可能要复杂写,修改栏目的所属目录,按照步骤来:

控制器层:

//更改栏目,名称,栏目的所属栏目

    public function edit(){

    $cate=new CateModel();//实例化

    //获取表单数据

    if(request()->isPost()){

    $data=input('post.');

    $save=$cate->save($data,['id'=>$data['id']]);//更改数据,$data['id']更改栏目的上级目录

    if($save){

    $this->success('添加成功',url('lst'));

    }else{

    $this->error('添加失败');

    }

    }

    //前端输出数据,要先查询相应的数据


    $cates=$cate->find(input('id'));//获得需要更改的id数据,这里在前端模板中用input隐藏传入

    $cateres=$cate->catetree();//获得所有数据

    $this->assign(array(//赋值

             'cateres'=>$cateres,

             'cates'=>$cates,

    ));

    return view();

    }

V层引入文件edit.htm

<form class="form-horizontal" role="form" action="" method="post">

                        <input type="hidden" name="id" value="{$cates.id}" />/*这里要传入所属栏目的id,不过前端要隐藏*/

                        <div class="form-group">

                            <label for="username" class="col-sm-2 control-label no-padding-right">上级栏目</label>

                            <div class="col-sm-6">

                                <select name="pid">

                                    <option value="0">顶级栏目</option>

                                    {volist name="cateres" id="cate"}

                                    <option {if condition="$cates['pid'] eq $cate['id']"}selected="selected"{/if} value="{$cate.id}">{if condition="$cate['level'] neq 0"}|{/if}<?php echo str_repeat('-', $cate['level']*4)?>{$cate.catename}</option>

                                    {/volist}

                                </select>

                            </div>

                            <p class="help-block col-sm-4 red">* 必填</p>

                        </div>

                        <div class="form-group">

                            <label for="username" class="col-sm-2 control-label no-padding-right">栏目名称</label>

                            <div class="col-sm-6">

                                <input class="form-control"  placeholder="" value="{$cates.catename}" name="catename" required="" type="text">

                            </div>

                            <p class="help-block col-sm-4 red">* 必填</p>

                        </div>

                       

                        <div class="form-group">

                            <label for="group_id" class="col-sm-2 control-label no-padding-right">栏目类型</label>

                            <div class="col-sm-6">

                                <div class="radio" style="float:left; margin-right:10px;">

                                    <label>

                                        <input {if condition="$cates['type'] eq 1"}checked="checked"{/if} name="type" value="1"  type="radio">

                                        <span class="text">文章列表</span>

                                    </label>

                                </div>

                                <div class="radio" style="float:left; margin-right:10px;">

                                    <label>

                                        <input {if condition="$cates['type'] eq 2"}checked="checked"{/if} name="type" class="inverted" value="2" type="radio">

                                        <span class="text">单页</span>

                                    </label>

                                </div>

                                <div class="radio" style="float:left; margin-right:10px;">

                                    <label>

                                        <input {if condition="$cates['type'] eq 3"}checked="checked"{/if} name="type" class="inverted" value="3" type="radio">

                                        <span class="text">图片列表</span>

                                    </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>

标签: thinkphp5无限级分类

发表评论:

whatsapp营销