$this->loadModel('Product');
$this->set('products',$this->Product->find('list',array('product'=>array('products.name' => 'products.price'))));
$this->set(compact('products'));
I am trying to make it so I can display both the product name and it's price beside each other in the function I am using. So when the drop down is selected, instead of just being "productname" it would be like "productname - $price".
I am pretty sure this is all the code that needsto be seen.
Simple add the following line in your Product Model:
public $virtualFields = array('name_price' => 'concat(Product.name, "-", Product.price)');
and try the following code to fetch:
$this->loadModel('Product');
$this->set('products',$this->Product->find('list',array('fields'=>array('Product.name_price' => 'Product.price'))));
$this->set(compact('products'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With