Mysterious error of yii2

Hi guys,

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 – yii\base\InvalidConfigException

Unable to locate message source for category 'mtrelt'.


throw new InvalidConfigException("Unable to locate message source for category '$category'.")


2. in ...\vendor\yiisoft\yii2\i18n\I18N.php at line 88 – yii\i18n\I18N::getMessageSource('mtrelt')

3. in ...\vendor\yiisoft\yii2\BaseYii.php at line 509 – yii\i18n\I18N::translate('mtrelt', 'Data can't be deleted because it...', [], 'de-DE')


4. in ...\vendor\mootensai\yii2-relation-trait\RelationTrait.php at line 312 – yii\BaseYii::t('mtrelt', 'Data can't be deleted because it...')




Here is model:




<?php


namespace common\modules\lookup\models\base;


use Yii;

use mootensai\behaviors\UUIDBehavior;


class LPersonArt extends \yii\db\ActiveRecord

{

    use \mootensai\relation\RelationTrait;




    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(\common\modules\erweiterung\models\EAppEinstellungArt::className(), ['id_person_art' => 'id']);

    }


    public function getLKontaktVerwendungszwecks()

    {

        return $this->hasMany(\common\modules\lookup\models\LKontaktVerwendungszweck::className(), ['id_person_art' => 'id']);

    }


    public function getPeople()

    {

        return $this->hasMany(\common\modules\basis\models\Person::className(), ['id_person_art' => 'id']);

    }


    public function behaviors()

    {

        return [

            'uuid' => [

                'class' => UUIDBehavior::className(),

                'column' => 'id',

            ],

        ];

    }


    public static function find()

    {

        return new \common\modules\lookup\models\LPersonArtQuery(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 yii\helpers\Html;

use yii\widgets\ActiveForm;

?>


<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(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

        'type' => \jlorente\remainingcharacters\RemainingCharacters::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(\jlorente\remainingcharacters\RemainingCharacters::classname(), [

        'type' => \jlorente\remainingcharacters\RemainingCharacters::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>



If I read correctly, the data does import? But if you later attempt an edit on one of those, an error?

Is it perhaps a bad datatype, or the way Yii2 quotes, or a special symbol. I’d set up a small test database and make a chart with pencil and paper and log what works and not.

Also I would experiment with bringing in the data with normal only PDO (No active record) and see if the errors persist.

Is directory mtrelt exist?

Show us your config file where you configure i18n translations

This.

You should have a file named [color="#008800"][size="2"]mtrelt.php[/size][/color][size="2"] under your translation directory (i.e. messages/) with an array of strings.[/size]

If you just delete the offending record, the [color="#660066"][size="2"]Invalid[/size][/color] [color="#660066"][size="2"]Configuration[/size][/color] [color="#666600"][size="2"]–[/size][/color][size="2"] yii[/size][color="#666600"][size="2"]\[/size][/color][color="#000088"][size="2"]base[/size][/color][color="#666600"][size="2"]\[/size][/color][color="#660066"][size="2"]InvalidConfigException[/size][/color][size="2"] may appear again when [/size][size="2"]the [/size][color="#008800"][size="2"]yii2-relation-trait[/size][/color][size="2"] extension needs to show another message.[/size]

[size="2"]-- Edit --[/size]

[size=2]May be this can help you, same error[/size]

https://github.com/mdmsoft/yii2-admin/issues/67

[size=2]which was corrected by adding i18n translations.[/size]

I have following mtrelt.php-files in my application:


...\vendor\mootensai\yii2-relation-trait\messages\en\mtrelt.php

and


...\vendor\mootensai\yii2-relation-trait\messages\id-ID\mtrelt

There is no configuration of i18n in my application

This is content of mtrelt.php


<?php

/**

 * Message translations.

 *

 * This file is automatically generated by 'yii message/extract' command.

 * It contains the localizable messages extracted from source code.

 * You may modify this file by translating the extracted messages.

 *

 * Each array element represents the translation (value) of a message (key).

 * If the value is empty, the message is considered as not translated.

 * Messages that no longer need translation will have their translations

 * enclosed between a pair of '@@' marks.

 *

 * Message string can be used with plural forms format. Check i18n section

 * of the guide for details.

 *

 * NOTE: this file must be saved in UTF-8 encoding.

 */

return [

    'Data can\'t be deleted because it\'s still used by another data.' => 'Data tidak bisa dihapus karena masih digunakan oleh data lain.',

];

I added following code into components of /config/main-local.php:




            'i18n' => [

                'translations' => [

                    '*' => [

                        'class' => 'yii\i18n\PhpMessageSource',

                        'basePath' => '@app/messages', // if advanced application, set @frontend/messages

                        'sourceLanguage' => 'de',

                    ],

                ],

            ],



If I tr to update record, I will get no error any more but it won’t be updated. I will get following message,instead:




Bitte korrigieren Sie die folgenden Fehler:


    Data can't be deleted because it's still used by another data.



I don’t want to delete record. I want to update record(see Controller). Using phpmyadmin,I’m able to update record. Deleting will be avoided by referentiel integrity, but not updating!

I know by now, why it’s not possible:File


…\vendor\mootensai\yii2-relation-trait\RelationTrait.php 

of mootensai will prevent updating records which have m:n-cardinality and whose primary key will be used by a chlid tabel(as foreign key)

Deleting of those files will be prevented of database 'cause of referentiel integrity. This Exception will be intercepted using try/catch. So, everything is all right,by now.

P.S.:Special expression of thanks to KVron. Ur link helped me solving my problem