夺命雷公狗ThinkPHP项目之----企业网站7之栏目的修改(主要用模型来验证字段)

我们照老,在控制器里面先查出我们所需要用到的数据:

 

然后直接遍历到模版上即可:

 

然后再开始写提交过来的数据处理问题(注意一定要接收修改页面通过隐藏域)而且我们刚才已经写好我们的model层了,所以直接用大D即可实现:

 

 

 

 

<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>后台管理</title>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Admin/css/main.css"/>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/libs/modernizr.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/jq18m.js"></script>
    <script type="text/javascript" src="__PUBLIC__/Admin/js/hileft.js"></script>
    
    
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/Ueditor/ueditor.config.js"></script>
        
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/Ueditor/ueditor.all.min.js"></script>
        <script type="text/javascript" charset="utf-8" src="__PUBLIC__/Ueditor/lang/zh-cn/zh-cn.js"></script>
    


    
</head>
<body>

<include file="Public/header" />

<div class="container clearfix">
    <include file="Public/left" />
    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/jscss/admin/design/">首页</a><span class="crumb-step">&gt;</span><a class="crumb-name" href="/jscss/admin/design/">作品管理</a><span class="crumb-step">&gt;</span><span>新增作品</span></div>
        </div>
        <div class="result-wrap">
            <div class="result-content">
                <form action="" method="post" id="myform" name="myform" enctype="multipart/form-data">
                    <table class="insert-tab" width="100%">
                        <tbody>
                        <tr>
                            
                            <th width="120"><i class="require-red">*</i>上级分类:</th>
                            <td>
                                <select name="cate_pid" id="catid" class="required">
                                    <option value="">顶级分类</option>
                                </select>
                            </td>
                        </tr>
                        
                            <tr>
                                <th><i class="require-red">*</i>栏目中文名:</th>
                                <td>
                                    <input class="common-text required" id="title" name="cate_name" size="50" value="{$vo['cate_name']}" type="text">
                                </td>
                            </tr>
                            
                            <tr>
                                <th><i class="require-red">*</i>栏目英文名:</th>
                                <td><input class="common-text" name="cate_ename" size="50" value="{$vo['cate_ename']}" type="text"></td>
                            </tr>
                            
                            <tr>
                                <th>栏目关键词:</th>
                                <td><input class="common-text" name="cate_keywords" size="50" value="{$vo['cate_keywords']}" type="text"></td>
                            </tr>
                            
                            <tr>
                                <th>栏目图片:</th>
                                <td>
                                <if condition="$vo['cate_pic'] eq ''">
                                <div style="color:red;">抱歉目前没有图片数据</div>
                                <else/>
                                <img src="/{$vo['cate_pic']}" width="100" height="60">
                                </if>
                                <input name="cate_pic" id="" type="file"><!--<input type="submit" onclick="submitForm('/jscss/admin/design/upload')" value="上传图片"/>--></td>
                            </tr>
                            
                            <tr>
                                <th>栏目描述:</th>
                                <td>
                                    <textarea name="cate_desc" style="margin: 0px; width: 609px; height: 157px;">{$vo['cate_desc']}</textarea>
                                </td>
                            </tr>
                            
                            
                            <tr>
                                <th>栏目类型:</th>
                                <if condition="$vo['cate_type'] eq 0">
                                <td>
                                    封面栏目:<input type="checkbox" checked name="cate_type" value="0"> <br />
                                    列表栏目:<input type="checkbox" name="cate_type" value="1"> <br />
                                    产品栏目:<input type="checkbox" name="cate_type" value="2">
                                </td>
                                <elseif condition="$vo['cate_type'] eq 1" />
                                <td>
                                    封面栏目:<input type="checkbox" name="cate_type" value="0"> <br />
                                    列表栏目:<input type="checkbox" checked name="cate_type" value="1"> <br />
                                    产品栏目:<input type="checkbox" name="cate_type" value="2">
                                </td>
                                <elseif condition="$vo['cate_type'] eq 2" />
                                <td>
                                    封面栏目:<input type="checkbox" name="cate_type" value="0"> <br />
                                    列表栏目:<input type="checkbox" name="cate_type" value="1"> <br />
                                    产品栏目:<input type="checkbox" checked name="cate_type" value="2">
                                </td>
                                </if>
                            </tr>
                            
                            
                            <tr>
                                <th>栏目内容:</th>
                                <td>
                                    <textarea id="content" name="cate_content">{$vo['cate_content']}</textarea>
                                </td>
                            </tr>
                            <input type="hidden" name="cate_id"  value="{$vo['cate_id']}" />
                            <tr>
                                <th></th>
                                <td>
                                    <input class="btn btn-primary btn6 mr10" value="提交" type="submit">
                                    <input class="btn btn6" onclick="history.go(-1)" value="返回" type="button">
                                </td>
                            </tr>
                        </tbody></table>
                </form>
            </div>
        </div>

    </div>
    <!--/main-->
</div>
<script type="text/javascript">
    UE.getEditor('content',{initialFrameWidth:890,initialFrameHeight:550});
    //initialFrameWidth: null 这样就是他自动设置大小
</script>
<style type="text/css">
    #edui2 div{
        height:25px;
    }
</style>
</body>
</html>

 

 

public function edit(){
        $id = I('id');
        $vo = M('Category')->find($id);
        $this -> assign('vo',$vo);
        if(IS_POST){
            $data['cate_id'] = I('cate_id');
            $data['cate_name'] = I('cate_name');
            $data['cate_ename'] = I('cate_ename');
            $data['cate_keywords'] = I('cate_keywords');
            $data['cate_desc'] = I('cate_desc');
            $data['cate_type'] = I('cate_type');
            $data['cate_pid'] = I('cate_pid');
            $data['cate_content'] = I('cate_content');
            if($_FILES['cate_pic']['tmp_name']!=''){
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   = 3145728 ;// 设置附件上传大小
                $upload->exts      = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  = './';  //这个一定要加否则很容易中招
                $upload->savePath  =      'Public/Uploads/'; // 设置附件上传目录
                $info   =   $upload->uploadOne($_FILES['cate_pic']);
                if($info){
                    //删除原来的图片
                    $cp = M('Category')->find($id);
                    unlink($cp['cate_pic']);
                    // 上传成功 获取上传文件信息  
                    //这里组装sql语句,让图片融入$data['pic']里面
                    $data['cate_pic'] = $info['savepath'].$info['savename'];
                }else{
                    $this->error($upload->getError());
                }
            }
            $mod = D('Category');
            if($mod-> create($data)){
                if($mod->save()){
                    $this->success('添加栏目成功',U('Category/lists'));
                }else{
                    $this ->error('添加栏目失败');
                }
            }else{
                $this->error($brandModel->getError());
            }
        }
        $this->display();
    }

 

 

这样即可实现

posted @ 2016-04-23 15:11  夺命雷公狗  阅读(200)  评论(0编辑  收藏  举报