cakephp cakedc搜索插件按名称值和条件筛选
我有一个cakephp 3.0运行良好的cakedc搜索插件,但希望有更高级的搜索过滤器,如:cakephp cakedc搜索插件按名称值和条件筛选,cakephp,cakedc,cakephp-search-plugin,Cakephp,Cakedc,Cakephp Search Plugin,我有一个cakephp 3.0运行良好的cakedc搜索插件,但希望有更高级的搜索过滤器,如: city = 'Los Angeles'; city != 'Los Angeles'; city LIKE '%Angeles%'; city LIKE 'Los%'; city NOT LIKE '%Angeles%'; city NOT LIKE 'Los%'; etc... 所以我希望添加2个下拉选择和1个文本输入来实现这一点 “city”将位于db字段的下拉列表中 =,!=,,像%?%,像
city = 'Los Angeles';
city != 'Los Angeles';
city LIKE '%Angeles%';
city LIKE 'Los%';
city NOT LIKE '%Angeles%';
city NOT LIKE 'Los%';
etc...
所以我希望添加2个下拉选择和1个文本输入来实现这一点
“city”将位于db字段的下拉列表中
=,!=,,像%?%,像%?,不像?%的条件将是下拉列表
“los angeles”搜索值将被输入。计算出来,可能并不完美,但似乎工作正常: 视图:
我清理代码,只是因为我们看起来是一个大代码。 换句话说,为什么在条件选择输入中包含空选项?使用默认搜索条件是否会更好? Saludos对不起,我不明白你需要什么帮助。。。
<?php echo $this->Form->input('dbfield', ['label' => 'Field', 'options' => ['' => '', 'region' => 'Region', 'city' => 'City', 'keyword' => 'Keyword']]); ?>
<?php echo $this->Form->input('dbconditions', [
'label' => 'Condition',
'options' => [
'' => '',
'contains' => 'contains',
'doesnotcontain' => 'does not contain',
'beginswith' => 'begins with',
'endswith' => 'ends with',
'isequalto' => 'is equal to',
'isnotequalto' => 'is not equal to',
],
]); ?>
<?php echo $this->Form->input('dbvalue', ['label' => 'Value', 'class' => 'form-control input-sm']); ?>
public $filterArgs = [
'dbfield' => [
'type' => 'finder',
'finder' => 'conds0',
],
'dbconditions' => [
'type' => 'finder',
'finder' => 'conds0',
],
'dbvalue' => [
'type' => 'finder',
'finder' => 'conds',
],
];
public function findConds0(Query $query, $options = []) {
}
public function findConds(Query $query, $options = []) {
if($options['data']['dbconditions'] == 'contains') {
$conditions = [
$options['data']['dbfield'] . ' LIKE' => '%' . $options['data']['dbvalue'] . '%',
];
}
if($options['data']['dbconditions'] == 'doesnotcontain') {
$conditions = [
$options['data']['dbfield'] . ' NOT LIKE' => '%' . $options['data']['dbvalue'] . '%',
];
}
if($options['data']['dbconditions'] == 'beginswith') {
$conditions = [
$options['data']['dbfield'] . ' LIKE' => $options['data']['dbvalue'] . '%',
];
}
if($options['data']['dbconditions'] == 'endswith') {
$conditions = [
$options['data']['dbfield'] . ' LIKE' => '%' . $options['data']['dbvalue'],
];
}
if($options['data']['dbconditions'] == 'isequalto') {
$conditions = [
$options['data']['dbfield'] => $options['data']['dbvalue'],
];
}
if($options['data']['dbconditions'] == 'isnotequalto') {
$conditions = [
$options['data']['dbfield'] . ' != ' => $options['data']['dbvalue'],
];
}
return $query->where($conditions);
}