2013-12-10 42 views
0

我目前正在检索数据并设置为视图来填充输入选择字段,尽管我发现它的名称只显示选择字段中的ID。下面是代码Cakephp数据检索只有ID

  // retrieve new lead list 
    $arrList = $this->NewLead->find('list', array('order' => 'newlead_name'));   

    //set to the view 
    $this->set(compact('arrList')); 

这里是鉴于代码

echo $this->Form->select('NewLead', $arrList, array('multiple' => 'true', 'id' => 'NewLeadList')); 

我做了什么错?

回答

1
// retrieve new lead list 
    $arrList = $this->NewLead->find('list', array('fields'=>array("id","name_whatever"),'order' => 'newlead_name'));   

    //set to the view 
    $this->set(compact('arrList')); 
    //here is the code in view 
    echo $this->Form->select('NewLead', array('multiple' => 'true', 'id' => 'NewLeadList','options'=>$arrList)); 
+0

谢谢。我通过在模型中添加public $ displayField = newlead_name来解决了问题。 – Patrick

+0

顺便说一下,这是我们这样做的方式...... –

+0

你也可以简单地遵循约定,即将view var定义为'newLeads',这样窗体帮助程序就会自动将其选中。 http://book.cakephp.org/2.0/en/core-libraries/helpers/form.html#creating-form-elements @Patrick – ndm