public function insert($runValidation = true, $attributes = null)
    {
        if ($runValidation && !$this->validate($attributes)) {
            return false;
        }
        $db = static::getDb();
        if ($this->isTransactional(self::OP_INSERT) && $db->getTransaction() === null) {
            $transaction = $db->beginTransaction();
            try {
                $result = $this->insertInternal($attributes);
                if ($result === false) {
                    $transaction->rollBack();
                } else {
                    $transaction->commit();
                }
            } catch (\Exception $e) {
                $transaction->rollBack();
                throw $e;
            }
        } else {
            $result = $this->insertInternal($attributes);
        }

        return $result;
    }
public function insert($runValidation = true, $attributes = null)
    {
        if ($runValidation && !$this->validate($attributes)) {
            return false;
        }
        $db = static::getDb();
        if ($this->isTransactional(self::OP_INSERT) && $db->getTransaction() === null) {
            $transaction = $db->beginTransaction();
            try {
                $result = $this->insertInternal($attributes);
                if ($result === false) {
                    $transaction->rollBack();
                } else {
                    $transaction->commit();
                }
            } catch (\Exception $e) {
                $transaction->rollBack();
                throw $e;
            }
        } else {
            $result = $this->insertInternal($attributes);
        }

        return $result;
    }
public function insert ( $ runValidation = true , $ attributes = null ) { if ( $ runValidation && ! $ this -> validate ( $ attributes ) ) { return false ; } $ db = static :: getDb ( ) ; if ( $ this -> isTransactional ( self :: OP_INSERT ) && $ db -> getTransaction ( ) === null ) { $ transaction = $ db -> beginTransaction ( ) ; try { $ result = $ this -> insertInternal ( $ attributes ) ; if ( $ result === false ) { $ transaction -> rollBack ( ) ; } else { $ transaction -> commit ( ) ; } } catch ( \ Exception $ e ) { $ transaction -> rollBack ( ) ; throw $ e ; } } else { $ result = $ this -> insertInternal ( $ attributes ) ; } return $ result ; }
Inserts a row into the associated Sphinx index using the attribute values of this record.

This method performs the following steps in order:

1. call [[beforeValidate()]] when `$runValidation` is true. If validation
fails, it will skip the rest of the steps;
2. call [[afterValidate()]] when `$runValidation` is true.
3. call [[beforeSave()]]. If the method returns false, it will skip the
rest of the steps;
4. insert the record into index. If this fails, it will skip the rest of the steps;
5. call [[afterSave()]];

In the above step 1, 2, 3 and 5, events [[EVENT_BEFORE_VALIDATE]],
[[EVENT_BEFORE_INSERT]], [[EVENT_AFTER_INSERT]] and [[EVENT_AFTER_VALIDATE]]
will be raised by the corresponding methods.

Only the [[changedAttributes|changed attribute values]] will be inserted.

For example, to insert an article record:

```php
$article = new Article();
$article->id = $id;
$article->genre_id = $genreId;
$article->content = $content;
$article->insert();
```

@param bool $runValidation whether to perform validation before saving the record.
If the validation fails, the record will not be inserted.
@param array $attributes list of attributes that need to be saved. Defaults to null,
meaning all attributes that are loaded from index will be saved.
@return bool whether the attributes are valid and the record is inserted successfully.
@throws \Exception in case insert failed.
Inserts a row into the associated Sphinx index using the attribute values of this record .