public function save(){
        if($this->beforeSave()){
            if($this->isNew()){
                $data = $this->_dirty;
                
                //insert
                if(false !== $rst = $this->_db->builder()->insert($this->getTable(), $data))
                {
                    if(is_string($this->getPK()) && $id = $this->_db->lastInsertId()){
                        $data[$this->getPK()] = $id;
                    }
                    $this->_data = $data;
                    $this->_dirty = array();
                    $this->_isNew = false;
                    $this->afterSave();
                    return $rst;
                }
            }
            else{
                if($this->isDirty()){
                    //update
                    $pkConditions = $this->buildPKConditions();
                    if(false !== $rst = $this->_db->builder()->update($this->getTable(), $this->_dirty, $pkConditions[0], $pkConditions[1])){
                        $this->_data = array_merge($this->_data, $this->_dirty);
                        $this->_dirty = array();
                        $this->afterSave();
                        return $rst;
                    }
                }
            }
        }
        
        return false;
    }
public function save(){
        if($this->beforeSave()){
            if($this->isNew()){
                $data = $this->_dirty;
                
                //insert
                if(false !== $rst = $this->_db->builder()->insert($this->getTable(), $data))
                {
                    if(is_string($this->getPK()) && $id = $this->_db->lastInsertId()){
                        $data[$this->getPK()] = $id;
                    }
                    $this->_data = $data;
                    $this->_dirty = array();
                    $this->_isNew = false;
                    $this->afterSave();
                    return $rst;
                }
            }
            else{
                if($this->isDirty()){
                    //update
                    $pkConditions = $this->buildPKConditions();
                    if(false !== $rst = $this->_db->builder()->update($this->getTable(), $this->_dirty, $pkConditions[0], $pkConditions[1])){
                        $this->_data = array_merge($this->_data, $this->_dirty);
                        $this->_dirty = array();
                        $this->afterSave();
                        return $rst;
                    }
                }
            }
        }
        
        return false;
    }
public function save ( ) { if ( $ this -> beforeSave ( ) ) { if ( $ this -> isNew ( ) ) { $ data = $ this -> _dirty ; //insert if ( false !== $ rst = $ this -> _db -> builder ( ) -> insert ( $ this -> getTable ( ) , $ data ) ) { if ( is_string ( $ this -> getPK ( ) ) && $ id = $ this -> _db -> lastInsertId ( ) ) { $ data [ $ this -> getPK ( ) ] = $ id ; } $ this -> _data = $ data ; $ this -> _dirty = array ( ) ; $ this -> _isNew = false ; $ this -> afterSave ( ) ; return $ rst ; } } else { if ( $ this -> isDirty ( ) ) { //update $ pkConditions = $ this -> buildPKConditions ( ) ; if ( false !== $ rst = $ this -> _db -> builder ( ) -> update ( $ this -> getTable ( ) , $ this -> _dirty , $ pkConditions [ 0 ] , $ pkConditions [ 1 ] ) ) { $ this -> _data = array_merge ( $ this -> _data , $ this -> _dirty ) ; $ this -> _dirty = array ( ) ; $ this -> afterSave ( ) ; return $ rst ; } } } } return false ; }
Save modified data to db

@return int|boolean
Save modified data to db