3
$this->loadModel('Product');
$this->set('products',$this->Product->find('list',array('product'=>array('products.name' => 'products.price'))));
$this->set(compact('products'));

我正在努力做到这一点,这样我就可以在我正在使用的功能中同时显示产品名称和价格。So when the drop down is selected, instead of just being "productname" it would be like "productname - $price".

我很确定这是所有需要查看的代码。

4

1 回答 1

6

只需在您的 : 中添加以下行Product Model

public $virtualFields = array('name_price' => 'concat(Product.name, "-", Product.price)');

并尝试以下代码来获取:

$this->loadModel('Product');
$this->set('products',$this->Product->find('list',array('fields'=>array('Product.name_price' => 'Product.price'))));
$this->set(compact('products'));
于 2012-08-06T05:44:40.643 回答