views:

27

answers:

1

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->getUser ( $id ) );
+1  A: 

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";
NAVEED
Thanks, but that didn't solve the problem. There must be some sort of a glitch here. Ill try to work this out
Janis Peisenieks
Place you code in your question.
NAVEED
Added the model and the controller part
Janis Peisenieks
I had an error in my code. Instead of doing $row->toArray() on it's own line, I should have added it to the fetchRow()->toArray().Thanks, solved!
Janis Peisenieks