2010-07-29 30 views
0

我在這裏遇到了一些問題。當我嘗試這個功能,這個錯誤:Zend_Form :: populate()error

Catchable fatal error: Argument 1 passed to Zend_Form::populate() must be an array, object given, called in [..] 

當我使用的print_r()來查找第一個參數的值,輸出是這樣的:

Zend_Db_Table_Row Object ([_data:protected] => Array ([id] => 4 [title] => sd [name] => KG [picture] => http://xx/images/mny4r64mqb.png [show] => 1 [body] =>KB 
) [..] 

所以我知道,我輸入的對象是一個數組。什麼可能導致這個問題? 模型

public function getUser($id) 
    { 
     $id = (int)$id; 
     $row = $this->fetchRow('id = ' . $id); 
     $row->toArray(); 
     if (!$row) { 
      throw new Exception("Could not find row $id"); 
     } 
     return $row;  
    } 

控制器:

$albums = new Admin_Model_Users(); 
        //print_r($albums->getUser($id)); 
        $form->populate ($albums->getUser ($id)); 

回答

1

你必須一個Zend_Db_Table_Row轉換爲使用指定者()數組,然後傳遞給填入()

Zend_Db_Table_Row

例子:

$bugs = new Bugs(); 
$row = $bugs->fetchRow($bugs->select()->where('bug_id = ?', 1)); 

// Get the column/value associative array from the Row object 
$rowArray = $row->toArray(); 

// Now use it as a normal array 
foreach ($rowArray as $column => $value) { 
    echo "Column: $column\n"; 
    echo "Value: $value\n"; 
+0

謝謝,但這並沒有解決問題。這裏肯定會出現一些故障。我試圖解決這個問題 – 2010-07-29 08:49:42

+0

把你的代碼放在你的問題中。 – NAVEED 2010-07-29 09:27:06

+0

添加了模型和控制器部分 – 2010-07-29 10:21:02