Article.php 控制器
//修改上传图片
public function edit(){
$input = input('post.');
$res = Db::table('bk_article')->where('id',input('id'))->find();
$this->assign(['res'=>$res]);
if(request()->isPost()){
if($_FILES['thumb']['tmp_name']) {
$file = request()->file('thumb');
//如果没有 上传图片
if(empty($file)) {
unset($input['thumb']);
}else{
//上传后 把图片移动到 /public/uploads 文件下
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
//如果成功 移动图片
if($info){
//保存图片 路径信息
$thumb = DS . 'uploads'.'/'.$info->getSaveName();
$input['thumb'] = $thumb;
//如果之前 有上传的图片logo 就删除之前那张 logo图片
if($res['thumb']){
unlink('.'.$res['thumb']);
}
}
}
}
//修改上传图片
$res2 = Db::table('bk_article')->where('id',input('id'))->update($input);
if($res2){
$this->success('修改成功!','lis');
}else{
$this->error('修改失败');
}
}
//无限极分类 下拉列表框
$cate = new CateModel();
$res = $cate->select();
$data = $cate->getTree($res);
$this->assign(['data'=>$data]);
//不修改 就跳转到修改页面
return view('article/edit');
}
edit.html 视图
<!DOCTYPE html>
<html><head>
<meta charset="utf-8">
<title>修改文章</title>
<meta name="description" content="Dashboard">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!--Basic Styles-->
<link href="/static/admin/style/bootstrap.css" rel="stylesheet">
<link href="/static/admin/style/font-awesome.css" rel="stylesheet">
<link href="/static/admin/style/weather-icons.css" rel="stylesheet">
<!--Beyond styles-->
<link id="beyond-link" href="/static/admin/style/beyond.css" rel="stylesheet" type="text/css">
<link href="/static/admin/style/demo.css" rel="stylesheet">
<link href="/static/admin/style/typicons.css" rel="stylesheet">
<link href="/static/admin/style/animate.css" rel="stylesheet">
<!-- <script src="/static/admin/ueditor/ueditor.all.min.js"></script>-->
<!-- <script src="/static/admin/ueditor/ueditor.config.js"></script>-->
<!-- <script src="/static/admin/ueditor/lang/zh-cn/zh-cn.js"></script>-->
</head>
<body>
<!-- 头部 -->
{include file="public/top" /}
<!-- /头部 -->
<div class="main-container container-fluid">
<div class="page-container">
<!-- Page Sidebar -->
{include file="public/left" /}
<!-- /Page Sidebar -->
<!-- Page Content -->
<div class="page-content">
<!-- Page Breadcrumb -->
<div class="page-breadcrumbs">
<ul class="breadcrumb">
<li>
<a href="#">系统</a>
</li>
<li>
<a href="{:url('admin/article/lis')}">文章管理</a>
</li>
<li class="active">修改文章</li>
</ul>
</div>
<!-- /Page Breadcrumb -->
<!-- Page Body -->
<div class="page-body">
<div class="row">
<div class="col-lg-12 col-sm-12 col-xs-12">
<div class="widget">
<div class="widget-header bordered-bottom bordered-blue">
<span class="widget-caption">修改文章</span>
</div>
<div class="widget-body">
<div id="horizontal-form">
<form class="form-horizontal" role="form" action="{:url('admin/article/edit')}" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="{$res.id}" />
<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="" name="title" value="{$res.title}" required="" type="text">
</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="" name="author" value="{$res.author}" required="" type="text">
</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="" name="keywords" value="{$res.keywords}" required="" type="text">
</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">
<textarea class="form-control" name="desc" style=" height: 100px">{$res.desc}</textarea>
</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 placeholder="" name="thumb" value="" type="file">
<img src="{$res.thumb}" height="70" style="margin:15px 0px;" />
</div>
<p class="help-block col-sm-4 red">* 必填</p>
</div>
<div class="form-group">
<label class="col-sm-2 control-label no-padding-right">所属栏目</label>
<div class="col-sm-6">
<select name="cateid">
<option value="0">顶级文章</option>
{volist name="data" id="cate"}
<option {if condition="$res['cateid'] == $cate['id']"}selected="selected"{/if} value="{$cate.id}"><?php
if($cate['level'] != 0){
echo '|';
echo str_repeat(' - ',$cate['level']*3);
}else{
echo str_repeat(' - ',$cate['level']*3);
}
?>
{$cate.catename}
</option>
{/volist}
</select>
</div>
</div>
<div class="form-group">
<label for="username" class="col-sm-2 control-label no-padding-right">内容</label>
<div class="col-sm-6">
<textarea id="content" name="content">{$res.content}</textarea>
</div>
<p class="help-block col-sm-4 red">* 必填</p>
</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>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /Page Body -->
</div>
<!-- /Page Content -->
</div>
</div>
<!--Basic Scripts-->
<script src="/static/admin/style/jquery_002.js"></script>
<script src="/static/admin/style/bootstrap.js"></script>
<script src="/static/admin/style/jquery.js"></script>
<!--Beyond Scripts-->
<script src="/static/admin/style/beyond.js"></script>
<script src="/static/admin//ueditor/ueditor.config.js"></script>
<script src="/static/admin//ueditor/ueditor.all.min.js"></script>
<script src="/static/admin//ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
//实例化编辑器
//建议使用工厂方法getEditor创建和引用编辑器实例,如果在某个闭包下引用该编辑器,直接调用UE.getEditor('editor')就能拿到相关的实例
UE.getEditor('content',{initialFrameWidth:670,initialFrameHeight:400,});
</script>
</body></html>
|