Zend_Form::populate() error
Ive got some kind of a problem here. When I try this function, it return this error:
Catchable fatal error: Argument 1 passed to Zend_Form::populate() must be an array, object given, called in [..]
When I used print_r() to find the values of the 1st argument, the output was this:
Zend_Db_Table_Row Object ( [_data:protected] => Array ( [id] => 4 [title] => sd [name] => KG [picture] => http://xx/images/mny4r64mqb.png [show] => 1 [body] =>KB
) [..]
So I know, that the object I input is an array. What could be causing this problem? The model
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;
}
The controller:
$albums = new Admin_Model_Users ();
//print_r($albums->getUser($id));
$form->populate ( $albums->get开发者_运维问答User ( $id ) );
You have to convert Zend_Db_Table_Row to array using toArray() and then pass to populate().
Zend_Db_Table_Row
Example:
$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";
精彩评论