virtual field are not working in cakephp

2019-08-01 01:36发布

my controller .

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

and i added below line in my model Time

public $virtualFields = array('name_price' => 'concat(Time.varaddress1, "-", Time.varaddress2)');

and my ctp file is below

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

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

but now in output i got nothing in select filed.!!

and when i echo $time i got `Array ( )

and i want in select field

<option>varaddress1,varaddress2</option>

1条回答
老娘就宠你
2楼-- · 2019-08-01 02:17

You need to change your controller code like as :

$times=$this->Time->find('list',array('fields'=>array('Time.id','Time.name_price')));
$this->set(compact('times'));
查看更多
登录 后发表回答