2013-12-10 40 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