php - 按不同表格过滤产品 - Cakephp 3.8
问题描述
朋友们,如果有人可以帮助我,我将不胜感激。
输入关键字后,我创建了一个字段来按品牌、州和城市过滤产品。当我有搜索输入并且品牌字段运行良好时。但是,当我添加更多字段时,例如州和城市,他不会搜索。
ProductsTable.php
.
$this->belongsTo('Users', [
'foreignKey' => 'user',
'joinType' => 'INNER',
]);
.
用户表.php
$this->hasMany('Products', [
'foreignKey' => 'user_id',
]);
最后,我做这样的过滤方法:
public function search()
{
$this->viewBuilder()->setLayout('search');
$product = $this->paginate = [
'contain' => ['Brands', 'Users'],
'conditions' => ['and' => [
'Products.name like' => '%'. $this->request->getQuery('search') . '%',
'Brands.id like' => '%'.$this->request->getQuery('brand').'%',
'Users.state like' => '%'.$this->request->getQuery('estate').'%',
'Users.city like' => '%'.$this->request->getQuery('city').'%',
]
],
'order' => ['Products.price' => 'ASC' ]
];
$this->set('products', $this->paginate($this->Products));
$this->set('_serialize', ['products', 'brands', 'users']);
}
该方法不会给出错误,但它会像我之前所说的那样进行过滤。
如果有人可以分析,我将不胜感激。
解决方案
推荐阅读
- node.js - NGINX proxy_pass 第二个位置块 504 网关超时
- ms-access - access 2016 中的变量选择语句
- excel-formula - 根据三个查找变量显示正确的值
- swift - 如果我根本不使用 iOS 框架,它们会包含在我的构建中吗?
- c++ - 在 multipass Ubuntu 20.10 下编译 c++ 时出现间歇性“找不到文件”错误
- google-apps-script - 使用 onChange 检测 Note 更改
- microsoft-graph-api - 从 Microsoft 团队频道获取所有消息和回复 - 图表分页
- c# - 是否可以从 MVVM 弹出 DisplayPromptAsync
- javascript - Javascript 循环值显示为未定义
- php - 将自定义设置添加到 WooCommerce 产品选项卡