php - Cakephp 3 搜索功能
问题描述
有一个关于 cakephp3 搜索功能的问题,是否可以在搜索表单中的两个表/控制器中进行搜索?
这是代码,我正在尝试从类别名称和产品名称中搜索,它们的关系是产品具有类别 ID
这是来自控制器的代码
$c = $this->request->getQuery('c');
if(!empty($c)) {
$this->loadModel('Categories');
$category = TableRegistry::get('Categories');
$query = $this->Products->find()->contain(['Categories'=>['Products']])
->where(['Categories.name LIKE' => '%' . $c. '%']);
}
$this->set(compact('c','query'));
$key = $this->request->getQuery('key');
if(!empty($key)) {
$products->where(['Products.name LIKE ' => '%'.$key.'%']);
}
$this->set(compact('key'));
这是来自 HTML 方面,我 name="c",它只搜索 c 而不是键,
<?php echo $this->Form->create(null, ['type' => 'get', 'valueSources' =>
'query'); ?>
<?php echo $this->Form->control('search', ['type' => 'hidden']); ?>
<input type="text" class="form-control" name="c" placeholder="Search...">
<span class="input-group-append">
<button type="submit">
<?php echo $this->Form->end(); ?>
有没有一种方法可以将两种搜索组合在一个表单中?
谢谢你的帮助
解决方案
推荐阅读
- pdf - Pdf文本阿拉伯语提取
- javascript - 在 Javascript 中过滤多行文本
- r - 从字符串赋值给变量
- angular - 延迟加载在Angular中的多个应用程序之间不起作用
- pandas - 按特定顺序减去值并将发票编号和日期替换为减去的值
- questdb - 如何将 MQTT 数据存储到 QuestDB?
- azure-web-app-service - Azure App Service:在高负载时重定向客户端请求
- python - 使用 SymPY 的 dsolve 求解临界阻尼振荡器的微分方程时出现的问题
- c++ - 为什么(无限)递归在clang(和gcc/g++)中使用and w/o -O3会给出不同的结果?
- gitlab-ci - 使用自定义执行器的 Gitlab 运行器无法上传工件