我在控制器中接收到一个变量,我想用搜索变量进行绑定查询,我试试这个:
$search = $this->request->getPost('term');
$item = Item::find(
[
'columns' => 'name',
'conditions' => "name LIKE :searchT: ",
'bind' => [
'searchT' => '%'.$search.'%',
],
]
);
上面的代码返回了与 LIKE 限制不匹配的项目。
如果我通过字符串字面工作正常:
$item = Item::find(
[
'conditions' => "name LIKE '%Os%' ",
'columns' => 'name',
'limit' => 10,
]
);
查询:
<script type="text/javascript">
$( function() {
$("#itemSearch").autocomplete({
source: function ( request, response ) {
$.ajax({
type: "POST",
url: "/item/search",
dataType: "json",
data: {
term: request.term
},
contentType: "application/json",
success: function(data) {
response(data);
}
});
},
minLength: 2
})
})
</script>