-1

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.

Ravi Kant Mishra
  • 778
  • 1
  • 7
  • 13

1 Answers1

0

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;
  }
}
Ravi Kant Mishra
  • 778
  • 1
  • 7
  • 13