我想在頁面中獲取input框的值進(jìn)行數(shù)據(jù)庫查詢,我在custom.php中寫了查詢方法,需要傳參,但是不知道怎么將input框中的傳入查詢方法。
custom.php中的自定義函數(shù):
function my_recoWord($theme,$level) {
$sql = "select * from dr_app_mydata_2 where ".$theme1." LIKE CONCAT('%',theme,'%') and level =".$level1;
echo $sql;
$rt = \Phpcmf\Service::M()->db->query($sql);
if ($rt) {
$rows = $rt->getResultArray();
if(!$rows){
echo '暫無推薦';
}
foreach ($rows as $t) {
echo $t['name'] ;
echo ' ';
}
}
}模板中:
<label>{function name=my_recoWord param1=input框參數(shù)1 param2=input框參數(shù)2 cache=300}{$t}{/function}</label>
這種思路的話實現(xiàn)不了這種功能。
我的建議思路是,需要新建控制器,提交的動作的要通過ajax或者是純url傳遞到控制器中,然后在控制器器里面進(jìn)行數(shù)據(jù)業(yè)務(wù)邏輯處理,然后再返回到模板里面。
開源是一種精神,但不是義務(wù),幫忙是情分,不幫也不要抱怨,建議大家多研究代碼、多閱讀代碼、多翻閱社區(qū)歷史問題!
function postShow(){ console.log($('#dr_level').val()); console.log($('#dr_theme').val()); $.ajax({ url: "{dr_url('Xiezuowenzhang/html/getData')}", type: "GET", dataType: "json", data: { dr_level:$('#dr_level').val(), dr_theme:$('#dr_theme').val() }, success: function(index){ console.log(index); if (index.code == 1){ $('#postShow1').remove(); $('#recoword').append('<div id="postShow1">'+index.data+'</div>'); } }, error: function(index){ if (index.code == 0){ alert(index.msg); setTimeout(function(){ location.reload(); },1000); } } }); return false; }<div class="form-group" id="recoword"> <button onclick="postShow()">查看推薦詞匯</button> <div id="postShow1"></div> <!-- <label>{function name=my_recoWord param1=input框參數(shù)1 param2=input框參數(shù)2 cache=300}{$t}{/function}</label> --> </div>public function getData(){ $result = \Phpcmf\Service::M()->db->table('app_mydata_2')->select('name')->where('level',$_GET['dr_level'])->where("'".$_GET['dr_theme']."' LIKE CONCAT('%',theme,'%')")->get()->getResultArray(); for ($i=0; $i < count($result); $i++) { $data[$i] = $result[$i]['name']; } if ($result) { return json_encode([ 'code' => 1, 'msg' => '內(nèi)容獲取成功', 'data' => $data ]); }else{ return json_encode([ 'code' => 0, 'msg' => '內(nèi)容獲取失敗', 'data' => '' ]); } }按照插件開發(fā)的邏輯走