OmgDef / yii2-multilingual-behavior

Yii2 port of the yii-multilingual-behavior.
146 stars 60 forks source link

Cant't save language model. #71

Closed icekem closed 6 years ago

icekem commented 6 years ago

Hi.

I load model and get post data from form, but "lang" model fields doesn't save. And I don't have any errors after save()

        $Pr = Pr::find()->where(['pr_url'=>$url])->multilingual()->one();

        if(!$Pr) throw new NotFoundHttpException('Страница не найдена');

        if ($Pr->load(Yii::$app->request->post())) {
            if(!$Pr->save(false)){ print_r($Pr->getFirstErrors()); exit; }
        }

        return $this->render('update',['model'=>$Pr]);

My form fields:

                    <?= $form->field($model, 'pr_status')->textInput() ?>
                    <?= $form->field($model, 'prl_title_'.Lang::getCurrent()->url)->textInput() ?>
                    <?= $form->field($model, 'prl_teaser_'.Lang::getCurrent()->url)->textarea() ?>
                    <?= $form->field($model, 'prl_content_'.Lang::getCurrent()->url)->textarea() ?>

My behaivors param:

   public function behaviors()
    {
        return [
            'ml' => [
                'class' => MultilingualBehavior::className(),
                'languages' => [
                    'ru' => 'Russian',
                    'en-US' => 'English',
                ],
                'languageField' => 'prl_lang',
                //'localizedPrefix' => '',
                //'requireTranslations' => false',
                //'dynamicLangClass' => true',
                'langClassName' => PrLang::className(), // or namespace/for/a/class/PostLang
                'defaultLanguage' => 'ru',
                'langForeignKey' => 'prl_pr_id',
                'tableName' => "{{%PrLang}}",
                'attributes' => [
                    'prl_title', 'prl_content', 'prl_teaser'
                ]
            ],
        ];
    }

What i doing wrong?

OmgDef commented 6 years ago

You need to add validation rules to the Pr model for the multilingual attributes