/** * Populate static properties for this table module. * * @return void */ protected function _setup() { // get the database adapter if (!$this->_db) { $this->_db = $this->_getDefaultAdapter(); } if (!$this->_db instanceof Zend_Db_Adapter_Abstract) { throw new Zend_Db_Table_Exception('db object does not implement Zend_Db_Adapter_Abstract'); } // get the table name if (!$this->_name) { $this->_name = self::$_inflector->underscore(get_class($this)); } // get the table columns if (!$this->_cols) { $tmp = array_keys($this->_db->describeTable($this->_name)); foreach ($tmp as $native) { $this->_cols[$native] = self::$_inflector->camelize($native); } } // primary key if (!$this->_primary) { // none specified $table = $this->_name; throw new Zend_Db_Table_Exception("primary key not specified for table '{$table}'"); } elseif (!array_key_exists($this->_primary, $this->_cols)) { // wrong name $key = $this->_primary; $table = $this->_name; throw new Zend_Db_Table_Exception("primary key '{$key}' not in columns for table '{$table}'"); } }
/** * Constructor. */ public function __construct() { global $DIGGCONFIG; require_once DIGGMORE_DB_CONFIG; //$config = DiggmoreConfig::instance(); $adapter = $DIGGCONFIG['db']['adapter']; $params = $DIGGCONFIG['db']; $this->_db = Zend_Db::factory($adapter, $params); //Zend_Db_Table::setDefaultAdapter($this->_db); if (empty($this->_table)) { //Init default table name. $tbl = preg_replace('/^Db([a-zA-Z0-9]+)DAO$/', '\\1', get_class($this)); $inflector = new Zend_Db_Inflector(); $this->_table = $inflector->underscore($tbl); } }