controllers/DictionaryController.php
public function actionAddSynonyms($class, $headword, $word, $addMissing = true)
    {
        $extMgr = Yii::$app->rhoone->ext;
        /* @var $extMgr \rhoone\base\ExtensionManager */
        $model = $extMgr->getModel($class);
        $headwordModel = $model->getHeadwords()->andWhere(['word' => $headword])->one();
        if (!$headwordModel) {
            if ($addMissing) {
                $headwordModel = $model->setHeadword(new Headword(['word' => $headword]));
            } else {
                throw new Exception("The headword: `" . $headword . "` does not exist.");
            }
        }
        try {
            if (!$headwordModel->setSynonyms($word)) {
                throw new Exception("Failed to add synonyms: `" . $word . "`");
            }
        } catch (\Exception $ex) {
            throw new Exception($ex->getMessage());
        }
        echo "The synonyms `" . $word . "` is added to `" . $class . "`";
        return 0;
    }
public function actionAddSynonyms($class, $headword, $word, $addMissing = true)
    {
        $extMgr = Yii::$app->rhoone->ext;
        /* @var $extMgr \rhoone\base\ExtensionManager */
        $model = $extMgr->getModel($class);
        $headwordModel = $model->getHeadwords()->andWhere(['word' => $headword])->one();
        if (!$headwordModel) {
            if ($addMissing) {
                $headwordModel = $model->setHeadword(new Headword(['word' => $headword]));
            } else {
                throw new Exception("The headword: `" . $headword . "` does not exist.");
            }
        }
        try {
            if (!$headwordModel->setSynonyms($word)) {
                throw new Exception("Failed to add synonyms: `" . $word . "`");
            }
        } catch (\Exception $ex) {
            throw new Exception($ex->getMessage());
        }
        echo "The synonyms `" . $word . "` is added to `" . $class . "`";
        return 0;
    }
public function actionAddSynonyms ( $ class , $ headword , $ word , $ addMissing = true ) { $ extMgr = Yii :: $ app -> rhoone -> ext ; /* @var $extMgr \rhoone\base\ExtensionManager */ $ model = $ extMgr -> getModel ( $ class ) ; $ headwordModel = $ model -> getHeadwords ( ) -> andWhere ( [ 'word' => $ headword ] ) -> one ( ) ; if ( ! $ headwordModel ) { if ( $ addMissing ) { $ headwordModel = $ model -> setHeadword ( new Headword ( [ 'word' => $ headword ] ) ) ; } else { throw new Exception ( "The headword: `" . $ headword . "` does not exist." ) ; } } try { if ( ! $ headwordModel -> setSynonyms ( $ word ) ) { throw new Exception ( "Failed to add synonyms: `" . $ word . "`" ) ; } } catch ( \ Exception $ ex ) { throw new Exception ( $ ex -> getMessage ( ) ) ; } echo "The synonyms `" . $ word . "` is added to `" . $ class . "`" ; return 0 ; }
Add synonyms to class.
@param string $class
@param string $headword
@param string $word
@param boolean $addMissing
Add synonyms to class .