虚拟现场不CakePHP中工作(virtual field are not working in c

2019-10-21 06:01发布

我的控制器。

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

我下面加线在我的模型时间

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' 
));?>

但现在在输出我没有什么选择中提起。!

当我回声$时候我得到了'阵列()

我想在选择字段

<option>varaddress1,varaddress2</option>

Answer 1:

您需要更改等作为控制器代码:

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


文章来源: virtual field are not working in cakephp