實現方法
一、html部分改造
文件路徑:apps/admin/view/default/content/content.html
1.搜索【內容標題】,大致在195行,內容修改為:
</>code<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'}內容前增加如下代碼:
</>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;'>標題不能為空!</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
頁面中增加如下代碼即可:
</>code// 標題查重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); } }}
至此,功能增加完成。只檢測本模塊下的內容標題,不跨模塊檢測。