|
|||
|
Hi All,
I added three custom methods to an extended Zend_Db_Table class. $data is data from a Zend_Form object. Code:
public function updateAccount( array $data )
{
$Row = $this->fetchRow('user_id=\''.$data['userid'].'\'');
$this->addValuesToRow( $Row, $data );
$Row->save();
return $Row;
}
public function addAccount( array $data ) {
$Row = $this->createRow();
$this->addValuesToRow( $Row, $data );
$Row->save();
Return $Row;
}
/** maps the $data keys to columns in the table */
private static function addValuesToRow( &$row, array $data) {
foreach( array_keys($data) as $colkey) {
switch($colkey) {
case 'userid':
$row->USER_ID = $data[$colkey];
break;
case 'firstname':
$row->FNAME = $data[$colkey];
break;
/** other case statements */
}
}
}
The updateAccount method works fine, but he addAccount does not. I get a Zend_Db_Table_Row_Exception. The exception comes from Zend_Db_Table_Row_Abstract and the message is "Cannot refresh row as parent is missing". The data is saved in the database like expected but I get this exception... However, if I don't use the addValuesToRow method and just put the code in the addAccount method there is no error. Some how the pass-by-reference is changing the $Row object? Thanks for any help. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|