[英]Passing variable in conditions of method find() in Phalcon Framework
我在我的控制器中收到一个变量,我想用搜索变量进行绑定查询,我试试这个:
$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>
我的 $search 是空的,在我的 JQuery 中,我需要在 ajax 中添加一个标题:
...
source: function ( request, response ) {
$.ajax({
type: "POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
...
谢谢@Abhik Chakraborty
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.