示例#1
0
文件: Base.php 项目: lerre/framework
 /**
  * Destroy a record (delete from db)
  *
  * A custom implementation of destroy() can be written for a model by overriding
  * the _destroy() method. This will ensure that all callbacks are still executed
  *
  * <code>
  *  $binder = Binder::find(123);
  *  $binder->destroy();
  * </code>
  *
  * @return  boolean
  */
 public function destroy()
 {
     // All deletes are atomic
     $started = $this->connection->transactionStarted();
     if (!$started) {
         $this->connection->beginDbTransaction();
     }
     try {
         $this->_beforeDestroy();
         $this->_destroy();
         $this->_afterDestroy();
         if (!$started) {
             $this->connection->commitDbTransaction();
         }
         return true;
     } catch (Exception $e) {
         $this->connection->rollbackDbTransaction(false);
         return false;
     }
 }