virtual field are not working in cakephp

寵の児 提交于 2019-12-13 00:33:29

问题


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:


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


来源:https://stackoverflow.com/questions/26749934/virtual-field-are-not-working-in-cakephp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!