如何在CakePHP3中获得两个给定值之间的值

如何在CakePHP3中获得两个给定值之间的值,cakephp,cakephp-3.0,Cakephp,Cakephp 3.0,我想使用以下查询获取具有指定价格范围的产品,但出现以下错误: 无法将值转换为字符串InvalidArgumentException 此处产品价格为varchar(100)型。请帮我解决这个问题。我想这对你有帮助 $product_List = $this->Products->find('all') ->where(function ($exp) use($min,$max) { return $exp-&

我想使用以下查询获取具有指定价格范围的产品,但出现以下错误:

无法将值转换为字符串InvalidArgumentException

此处产品价格为varchar(100)型。请帮我解决这个问题。

我想这对你有帮助

$product_List = $this->Products->find('all')
                ->where(function ($exp) use($min,$max) {
                    return $exp->between('product_price', $min, $max); //Consider $min=100 ; $max =1000; product_price BETWEEN 100 AND 1000;
                });
另一种方式

$product_List = $this->Products->find('all')
            ->where(['product_price <=' => $max, 'product_price >=' => $min]);
$product\u List=$this->Products->find('all'))
->式中(['product_price='=>$min]);

@GregSchmidt的可能重复项:我的问题是关于使用between时出现的错误,无法将值转换为字符串InvalidArgumentException。您是否阅读了链接的问题?他们使用的是完全相同的“between?and?”格式,这在CakePHP 3中是不受支持的,答案告诉他们如何修复它。之所以会出现错误,是因为Cake基本上是试图通过将条件的值部分直接附加到关键部分(
array('k'=>v')
转换为
k=“v”)来进行查询
),但您的值部分是一个数组,它“无法转换为字符串”。谢谢Greg Schmidt。
$product_List = $this->Products->find('all')
            ->where(['product_price <=' => $max, 'product_price >=' => $min]);