在cakephp中虚拟字段不起作用

时间:2014-11-05 04:52:45

标签: cakephp cakephp-2.0

我的控制员。

$times=$this->Time->find('list',array('fields'=>$this->Time->virtualFields['name_price'] ));
$this->set('time',compact($times));

我在我的模型Time

中添加了以下行
public $virtualFields = array('name_price' => 'concat(Time.varaddress1, "-", Time.varaddress2)');

我的ctp文件在

之下
<?echo $this->Form->input('intaddressid', array(
'options' => $time,'label'=>false,'empty' => '(Select  Information)'

 ,'class' => 'form-control border_none' 
));?>

但现在在输出中我没有选择任何文件。!!

当我回复$ time时,我得到了'Array()

我希望在选择字段

<option>varaddress1,varaddress2</option>

1 个答案:

答案 0 :(得分:2)

您需要更改控制器代码,如:

$times=$this->Time->find('list',array('fields'=>array('Time.id','Time.name_price')));
$this->set(compact('times'));