How to change Zend_Db_Table name within a Model to insert in multiple tables
Posted
by jwhat
on Stack Overflow
See other posts from Stack Overflow
or by jwhat
Published on 2010-03-12T23:03:19Z
Indexed on
2010/03/12
23:07 UTC
Read the original article
Hit count: 256
Using Zend Framework, I've created a Model to insert a record into a database. My question is, after $this->insert($data)
how can I switch the active table so that I can insert a record into another table?
Here's my code so far:
class Model_DbTable_Foo extends Zend_Db_Table_Abstract
{
protected $_name = 'foo';
public function addFoo($params)
{
$data = array(
'foo' => $params['foo'],
);
$this->insert($data);
$foo_id = $this->getAdapter()->lastInsertId();
$data2 = array(
'bar' => $params['bar']
);
// I need to change the Db Table name here.
$this->insert($data2);
$bar_id = $this->getAdapter()->lastInsertId();
}
}
© Stack Overflow or respective owner