2011-05-18 107 views
0

下面的函數返回一個帶有字段名稱的數組,但我也想包含字段中的數據。CakePHP - 從表中獲取數據

我該怎麼做?我是CakePHP的新手。

function init_form($models) 
{ 
    foreach($models as $model=> $value) 
    { 

     $this->model = new $value; 

     $columns = $this->model->schema(); 

     //Extract field names from array 
     $j = 0; 
     foreach($columns as $col => $val) {     
      $arr[$value][$j] = $col; 
      $j++; 
     } 

     if(!empty($model)) 
     { 
      $arr['associated_table'][$value]=$model; 
     } 
    } 

    return $arr; 
} 

FYI: 我試圖按照本教程 http://bakery.cakephp.org/articles/Gkelly/2006/11/09/report-creator-component

我得到了它顯示的字段名稱。我只是無法獲取數據。

感謝

+0

提供關於您正在嘗試做什麼以及上述代碼位於何處的更多細節 - 模型,控制器? – 2011-05-18 21:24:55

+0

代碼是組件。我從控制器調用它。上面的鏈接會給你所有的細節 – Autolycus 2011-05-18 21:26:56

回答

1

檢查出retrieving data from your Modelfind()方法。我不熟悉你使用的組件。但是,考慮到您可以使用$this->model的型號,則可以使用它的find()方法,就像您使用schema() - $this->model->find()一樣。