I'm new to cakephp and I'm trying to do a search area to list some products that have their prices greater than a value, or lower than a value, and paginate it.
But when I try to do so, the result is totally different from what I've expected. When trying to get to know why was this happening, I had found out that my query was treating the value as String type instead of a Float, and it was messing up with the results.
No matter what I try, the type of value doesn't change, how do I make to change the type of the value on the query of cakePHP?
// the price value that comes from the input is formatted like this: '1.000,00'
$productsModel = $this->loadModel('Products');
$this->paginate = [
'contain' => [
'Archives', 'Categories', 'Favorites'
],
'conditions' => [
//here I've tried to do some conversions manually
'Products.price >=' => floatVal(str_replace(",", ".", str_replace(".", "", $data['lower_price']))),
'Products.price <=' => floatVal(str_replace(",", ".", str_replace(".", "", $data['greater_price']))
],
'limit' => 16
];
$products = $this->paginate($productsModel);
$this->set(compact('products'));
I was expecting that the query was generated like this:
SELECT * FROM products WHERE price >= 29.90;
But I have this instead:
SELECT * FROM products WHERE price >= '29.90';