Here is the basic code that I use for my zend framework models.
class Model_FormMapper extends Zend_Db_Table_Abstract
{
protected $_name = 'tblMapper';
protected $_primary = 'mapId';
public function insertColumns($arrData){
$db = Zend_Db_Table::getDefaultAdapter();
$sql = $this->insert($arrData);
$lastId = $this->_db->lastInsertId();
return $lastId;
}
}
One thing that I don't like in my models is initialisation of
adpter in each method.
$db = Zend_Db_Table::getDefaultAdapter();
Can any one tell me a better solution for writing zend models.
I got the answer I can set a database connection variable in registry and can use any where eg: $this->_db
.
class Model_FormMapper extends Zend_Db_Table_Abstract
{
protected $_name = 'tblMapper';
protected $_primary = 'mapId';
public function insertColumns($arrData){
$sql = $this->insert($arrData);
$lastId = $this->_db->lastInsertId();
return $lastId;
}
}