views:

219

answers:

2

Hi, is there a way of automatic converting from array to Zend_Db_Table_Row or Zend_Db_Table_Rowset?

Form Zend_Db_Table_Row you can get the array with toArray(), but I was wondering if there exits anything like opposite of that?

Till now I have been implementing a function fill($data) which took the array and than set the atributes of Zend_Db_Table_Row.

Of course array keys are the same as Zend_Db_Table_Row attributes.

Thanx!

+2  A: 

Check the Zend_Db_Table's fetchRow() method. There you can find it. I guess you can feed the array to the constructor like this:

$data = array(
        'table'   => $yourDbTableModel,
        'data'     => $yourArray,
        'readOnly' => $iGuessShouldBeZero,
        'stored'  => true
    );
$row = new Zend_Db_Table_Row($data);
Tomáš Fejfar
Thank you!both of you answers are very good!You both solved my problem!
Granit Luzhnica
+1  A: 

I think this should do the trick:

$myRow = new Zend_Db_Table_Row(
    array(
        'data' => array( /* your array with data */  )
    )
);

So, if you provide the constructor with a config array that holds a key 'data' that in it's turn holds an array with the data, you should be good.

For more info look into Zend_Db_Table_Row_Abstract in your Zend library.

fireeyedboy