實(shí)現(xiàn)方法
一、html部分改造
文件路徑:apps/admin/view/default/content/content.html
1.搜索【內(nèi)容標(biāo)題】,大致在195行,內(nèi)容修改為:
</>code<div class="layui-form-item"> <label class="LayUI-form-label">內(nèi)容標(biāo)題 <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="請(qǐng)輸入內(nèi)容標(biāo)題" class="LayUI-input"> </div> <div class="layui-form-mid layui-word-aux" id="email_msg">*</div></div>
2.頁面底部{include file='common/ueditor.html'}內(nèi)容前增加如下代碼:
</>code<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;'>標(biāo)題不能為空!</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 == "有重復(fù)") {$("#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
頁面中增加如下代碼即可:
</>code// 標(biāo)題查重public function checktitle(){ // 執(zhí)行 if ($_POST) { $title = post('title'); $id = post('id'); $mcode = post('mcode'); if (! $mcode) { error('傳遞的模型編碼參數(shù)有誤,請(qǐng)核對(duì)后重試!'); } $result = $this->model->findContentAll($mcode,$title); if($result){ success('有重復(fù)!', - 1); }else{ success('正常', - 1); } }}
至此,功能增加完成。只檢測(cè)本模塊下的內(nèi)容標(biāo)題,不跨模塊檢測(cè)。