Welcome, Guest. Register Now!
   
Mark Forums Read Mark Forums Read Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-15-2008, 05:53 PM
Junior Member
 
Join Date: Apr 2008
Posts: 4
Default Zend_Db_Table_Row_Abstract::Save() resfresh problem.

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 */
	    
	}
      }
  }
As you can see, addValuesToRow takes the keys in $data and map them to the column names in a table.

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:49 AM.