1
创建构造虚拟领域我有这个模型称为Product
从现有场
class Product extends AppModel {
public function __construct($id = false, $table = null, $ds = null) {
parent::__construct($id, $table, $ds);
$file_name = (preg_replace('/\\.[^.\\s]{3,4}$/', '', $this->field('product_picture')));
$ext = end((explode(".", $this->field('product_picture')))); # extra() to prevent notice
$this->virtualFields['product_picture_thumbnail'] = $file_name."350x350.".$ext;
}
}
它有一个域名为product_picture
这是像img1.png。我想创建一个基于该名称创建的虚拟字段,其代表类似img1350x350.png。
所以当我查询时,它会返回一个空列表。
$this->Product->find('all', array(
'fields' => array(
'product_picture',
'product_picture_thumbnail',
)));
我想知道你是否设法在下面尝试我的答案。 –