我想在filterArgs
(在模型中)中创建一个if else,如下所示:
public $filterArgs = array(
array('name' => 'to', 'type' => 'value' => 'Product.regular_price' ),
);
我希望该字段根据条件进行更改。
如果sale = 1,则字段为promo_price,否则字段为regular_price
我已尝试下面的代码(但不成功):
'field'=> 'Product.sale' => 1 ? 'Product.promo_price >=' : 'Product.regular_price >='
有人可以帮助我。非常感谢!
答案 0 :(得分:1)
我会在我的产品型号中创建一个虚拟字段
$virtualFields = array
(
'my_price' => 'IF(Product.sale = 1, Product.promo_price, Product.regular_price)';
)
public $filterArgs = array
(
'my_price' => array('type' => 'value'),
);