If I try to update records,I get following error without any ideas, what’s about or what this error could have been caused by. Furthermore, it’s strange, that this error only will be bred by records having been imported by a dump. There will be no error, if I will update a record having been created using saveasnew option. Unfortunately, I can’t delete this record in order to recreate it,’cause it would expel against referential integrity. Here is error:
Invalid Configuration – yiibaseInvalidConfigException Unable to locate message source for category 'mtrelt'. throw new InvalidConfigException("Unable to locate message source for category '$category'.") 2. in ...vendoryiisoftyii2i18nI18N.php at line 88 – yiii18nI18N::getMessageSource('mtrelt') 3. in ...vendoryiisoftyii2BaseYii.php at line 509 – yiii18nI18N::translate('mtrelt', 'Data can't be deleted because it...', [], 'de-DE') 4. in ...vendormootensaiyii2-relation-traitRelationTrait.php at line 312 – yiiBaseYii::t('mtrelt', 'Data can't be deleted because it...')
Here is model:
<?php namespace commonmoduleslookupmodelsbase; use Yii; use mootensaibehaviorsUUIDBehavior; class LPersonArt extends yiidbActiveRecord { use mootensairelationRelationTrait; public function relationNames() { return [ 'eAppEinstellungArts', 'lKontaktVerwendungszwecks', 'people' ]; } public function rules() { return [ [['person_art'], 'string', 'max' => 50], [['zieltabelle'], 'string', 'max' => 100], [['bemerkung'], 'string', 'max' => 255] ]; } public static function tableName() { return 'l_person_art'; } public function attributeLabels() { return [ 'id' => Yii::t('app', 'ID'), 'person_art' => Yii::t('app', 'Personengruppen'), 'zieltabelle' => Yii::t('app', 'Zieltabelle'), 'bemerkung' => Yii::t('app', 'Bemerkung'), ]; } public function getEAppEinstellungArts() { return $this->hasMany(commonmoduleserweiterungmodelsEAppEinstellungArt::className(), ['id_person_art' => 'id']); } public function getLKontaktVerwendungszwecks() { return $this->hasMany(commonmoduleslookupmodelsLKontaktVerwendungszweck::className(), ['id_person_art' => 'id']); } public function getPeople() { return $this->hasMany(commonmodulesbasismodelsPerson::className(), ['id_person_art' => 'id']); } public function behaviors() { return [ 'uuid' => [ 'class' => UUIDBehavior::className(), 'column' => 'id', ], ]; } public static function find() { return new commonmoduleslookupmodelsLPersonArtQuery(get_called_class()); } }
Here is Controller:
public function actionUpdate($id) { $model = new LPersonArt(); if (!Yii::$app->request->post('_asnew') == '1'){ $model = $this->findModel($id); } if ($model->load(Yii::$app->request->post()) && $model->saveAll()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', [ 'model' => $model, ]); } }
Here is view:
<?php use yiihelpersHtml; use yiiwidgetsActiveForm; ?> <div class="lperson-art-form"> <?php $form = ActiveForm::begin(); ?> <?= $form->errorSummary($model); ?> <?= $form->field($model, 'id', ['template' => '{input}'])->textInput(['style' => 'display:none']); ?> <?= $form->field($model, 'person_art')->widget(jlorenteremainingcharactersRemainingCharacters::classname(), [ 'type' => jlorenteremainingcharactersRemainingCharacters::INPUT_TEXTAREA, 'text' => Yii::t('app', '{n} characters remaining'), 'options' => [ 'rows' => '3', 'class' => 'col-md-12', 'maxlength' => 50, 'placeholder' => Yii::t('app', 'Write something') ] ]) ?> <?= $form->field($model, 'bemerkung')->widget(jlorenteremainingcharactersRemainingCharacters::classname(), [ 'type' => jlorenteremainingcharactersRemainingCharacters::INPUT_TEXTAREA, 'text' => Yii::t('app', '{n} characters remaining'), 'options' => [ 'rows' => '3', 'class' => 'col-md-12', 'maxlength' => 255, 'placeholder' => Yii::t('app', 'Write something') ] ]) ?> <div class="form-group"> <?php if (Yii::$app->controller->action->id != 'save-as-new'): ?> <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> <?php endif; ?> <?php if (Yii::$app->controller->action->id != 'create'): ?> <?= Html::submitButton(Yii::t('app', 'Save As New'), ['class' => 'btn btn-info', 'value' => '1', 'name' => '_asnew']) ?> <?php endif; ?> <?= Html::a(Yii::t('app', 'Cancel'), Yii::$app->request->referrer, ['class' => 'btn btn-danger']) ?> </div> <?php ActiveForm::end(); ?> </div>
Advertisement
Answer
Problem will be solved adding following code into components of
common/config/main-local.php
'i18n' => [ 'translations' => [ '*' => [ 'class' => 'yiii18nPhpMessageSource', 'basePath' => '@backend/messages', // if advanced application, set @frontend/messages 'sourceLanguage' => 'de', ], ], ],