Пример #1
0
 /**
  * 
  * Inserts the current record into the database, making calls to pre- and
  * post-insert logic.
  * 
  * @return void
  * 
  */
 protected function _insert()
 {
     // pre-insert logic
     $this->_preInsert();
     // modify special columns for insert
     $this->_modInsert();
     // apply record filters
     $this->filter();
     // get the data for insert
     $data = $this->_getInsertData();
     // try the insert
     try {
         // retain the inserted ID, if any
         $id = $this->_model->insert($data);
     } catch (Solar_Sql_Adapter_Exception_QueryFailed $e) {
         // failed at at the database for some reason
         $this->setInvalid('*', $e->getInfo('pdo_text'));
         throw $e;
     }
     // if there is an autoinc column, set its value
     foreach ($this->_model->table_cols as $col => $info) {
         if ($info['autoinc'] && empty($this->_data[$col])) {
             // set the value ...
             $this->_data[$col] = $id;
             // ... and skip all other cols
             break;
         }
     }
     // record was successfully inserted
     $this->_setSqlStatus(self::SQL_STATUS_INSERTED);
     // post-insert logic
     $this->_postInsert();
 }