【发布时间】:2017-10-19 11:13:11
【问题描述】:
我有这个模型叫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',
)));
【问题讨论】:
-
我想知道您是否设法在下面尝试我的答案。
标签: php sql cakephp cakephp-2.0