public function save()
    {

        //Set Defaults
        $this->setDefaultProperties();

        //Update timestamps
        $this->updateTimestamps();

        //Fire "before" events
        if (!$this->fireBeforeSaveEvent($this)) {
            return false;
        }

        $updating = $this->exists();
        if ($updating && !$this->fireBeforeUpdateEvent($this)) {
            return false;
        } elseif (!$this->fireBeforeCreateEvent($this)) {
            return false;
        }

        //Save or update
        $result = DB::store($this->bean);

        //fire "after" events
        $this->fireAfterSaveEvent($result);
        if ($updating) {
            $this->fireAfterUpdateEvent($result);
        } else {
            $this->fireAfterCreateEvent($result);
        }
        return $result;
    }
public function save()
    {

        //Set Defaults
        $this->setDefaultProperties();

        //Update timestamps
        $this->updateTimestamps();

        //Fire "before" events
        if (!$this->fireBeforeSaveEvent($this)) {
            return false;
        }

        $updating = $this->exists();
        if ($updating && !$this->fireBeforeUpdateEvent($this)) {
            return false;
        } elseif (!$this->fireBeforeCreateEvent($this)) {
            return false;
        }

        //Save or update
        $result = DB::store($this->bean);

        //fire "after" events
        $this->fireAfterSaveEvent($result);
        if ($updating) {
            $this->fireAfterUpdateEvent($result);
        } else {
            $this->fireAfterCreateEvent($result);
        }
        return $result;
    }
public function save ( ) { //Set Defaults $ this -> setDefaultProperties ( ) ; //Update timestamps $ this -> updateTimestamps ( ) ; //Fire "before" events if ( ! $ this -> fireBeforeSaveEvent ( $ this ) ) { return false ; } $ updating = $ this -> exists ( ) ; if ( $ updating && ! $ this -> fireBeforeUpdateEvent ( $ this ) ) { return false ; } elseif ( ! $ this -> fireBeforeCreateEvent ( $ this ) ) { return false ; } //Save or update $ result = DB :: store ( $ this -> bean ) ; //fire "after" events $ this -> fireAfterSaveEvent ( $ result ) ; if ( $ updating ) { $ this -> fireAfterUpdateEvent ( $ result ) ; } else { $ this -> fireAfterCreateEvent ( $ result ) ; } return $ result ; }
Stores a bean in the database. If the database schema is not compatible
with this bean and RedBean runs in fluid mode the schema
will be altered to store the bean correctly.
If the database schema is not compatible with this bean and
RedBean runs in frozen mode it will throw an exception.
This function returns the primary key ID of the inserted
bean.

The return value is an integer if possible. If it is not possible to
represent the value as an integer a string will be returned.

Usage:

<code>
$post = SampleModel::instance();
$post->title = 'my post';
$id = $post->save();
$post = SampleModel::load( $id );
$post->trash( $post );
</code>

In the example above, we create a new bean of SampleModel.
We then set the title of the bean to 'my post' and we
store the bean. The save() method will return the primary
key ID $id assigned by the database. We can now use this
ID to load the bean from the database again and delete it.


@return integer|string|boolean
Stores a bean in the database . If the database schema is not compatible with this bean and RedBean runs in fluid mode the schema will be altered to store the bean correctly . If the database schema is not compatible with this bean and RedBean runs in frozen mode it will throw an exception . This function returns the primary key ID of the inserted bean .