实现方法
一、html部分改造
文件路径:apps/admin/view/default/content/content.html
1.搜索【内容标题】,大致在195行,内容修改为:
<div class="layui-form-item">
<label class="layui-form-label">内容标题 <span class="layui-text-red">*</span></label>
<div class="layui-input-inline" style="width:80%;">
<input type="text" name="title" id="title" required lay-verify="required" placeholder="请输入内容标题" class="layui-input">
</div>
<div class="layui-form-mid layui-word-aux" id="email_msg">*</div>
</div>
2.页面底部{include file='common/ueditor.html'}内容前增加如下代码:
<script>
$(document).ready(function() {
$("input").blur(function() {
var $parent = $(this).parent();
$parent.find(".formtips").remove();
if ($(this).is("#title")) {
var title = this.value;
if (title == "") {
$("#email_msg").html("<span class='reg-error' style='display: inline;'>标题不能为空!</span>")
} else {
$.ajax({
url:"admin.php?p=/Content/checktitle/",
data:{
"formcheck":'{$formcheck}',
"mcode":{$get.mcode},
"title":title,
},
type:"POST",
dataType:"json",
success:function (data) {
if (data.data =="有重复") {
$("#email_msg").html("<a style='color:red'>"+data.data+"</a>");
}else {
$("#email_msg").html("<span style='color:#08a600'>"+data.data+"</span>")
}
}
})
}
}
});
});
</script>
二、PHP部分改造
文件路径:apps/admin/controller/content/ContentController.php
页面中增加如下代码即可:
// 文章标题查重
public function checktitle()
{
if ($_POST) {
$title = post('title');
$id = post('id');
$mcode = post('mcode');
if (!$mcode) {
error('传递的模型编码参数有误,请核对后重试!');
}
$result = $this->model->findContentAll($mcode,$title);
if($result){
success('有重复', - 1);
}else{
success('正常', - 1);
}
}
}
至此,功能增加完成。只检测本模块下的内容标题,不跨模块检测。
版权声明:本站部分图片来源于互联网,除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处,如有侵权请联系删除。。
还木有评论哦,快来抢沙发吧~