models/Headword.php
public static function add($word, $extension)
    {
        $headword = Headword::find()->where(['word' => $word, 'extension_guid' => $extension->guid])->one();
        if ($headword) {
            throw new InvalidParamException('The word: `' . $word . '` has existed.');
        }
        $headword = new Headword(['word' => $word, 'extension' => $extension]);
        $transaction = $headword->getDb()->beginTransaction();
        try {
            if (!$headword->save()) {
                if (YII_ENV !== YII_ENV_PROD) {
                    var_dump($headword->errors);
                }
                throw new InvalidParamException("Failed to add headword.");
            }
            $transaction->commit();
        } catch (\Exception $ex) {
            $transaction->rollBack();
            throw $ex;
        }
        return $headword;
    }
public static function add($word, $extension)
    {
        $headword = Headword::find()->where(['word' => $word, 'extension_guid' => $extension->guid])->one();
        if ($headword) {
            throw new InvalidParamException('The word: `' . $word . '` has existed.');
        }
        $headword = new Headword(['word' => $word, 'extension' => $extension]);
        $transaction = $headword->getDb()->beginTransaction();
        try {
            if (!$headword->save()) {
                if (YII_ENV !== YII_ENV_PROD) {
                    var_dump($headword->errors);
                }
                throw new InvalidParamException("Failed to add headword.");
            }
            $transaction->commit();
        } catch (\Exception $ex) {
            $transaction->rollBack();
            throw $ex;
        }
        return $headword;
    }
public static function add ( $ word , $ extension ) { $ headword = Headword :: find ( ) -> where ( [ 'word' => $ word , 'extension_guid' => $ extension -> guid ] ) -> one ( ) ; if ( $ headword ) { throw new InvalidParamException ( 'The word: `' . $ word . '` has existed.' ) ; } $ headword = new Headword ( [ 'word' => $ word , 'extension' => $ extension ] ) ; $ transaction = $ headword -> getDb ( ) -> beginTransaction ( ) ; try { if ( ! $ headword -> save ( ) ) { if ( YII_ENV !== YII_ENV_PROD ) { var_dump ( $ headword -> errors ) ; } throw new InvalidParamException ( "Failed to add headword." ) ; } $ transaction -> commit ( ) ; } catch ( \ Exception $ ex ) { $ transaction -> rollBack ( ) ; throw $ ex ; } return $ headword ; }
Add a headword.
@param string $word
@param Extension $extension
@return true|\static
@throws InvalidParamException
Add a headword .