2018-02-28 13:20
浏览 138


I'm using trntv/Yii2-starter-kit. How can I extract messages to DB? My config:

'*'=> [
         'class' => 'yii\i18n\DbMessageSource',
         'enableCaching' => YII_ENV_DEV,
         'cachingDuration' => 3600,
         'on missingTranslation' => ['\backend\modules\i18n\Module', 'missingTranslation']

My I18N file:

'languages' => ['uz','ru'],
'translator' => 'Yii::t',
'sort' => false,
'removeUnused' => true,
'only' => [
'ignoreCategories' => ['yii'],

I tryed:

php yii message @common/config/messages/_base.php

And php yii message But always it writes all messages to files: vendor/yiisoft/yii2/messages. How can I export messages to DB? Has anyone help?

图片转代码服务由CSDN问答提供 功能建议

我正在使用trntv / Yii2-starter-kit。 如何将消息提取到DB? 我的配置:

 '*'=>  [
'class'=>  'yii \ i18n \ DbMessageSource',
'enableCaching'=>  YII_ENV_DEV,
'cachingDuration'=>  3600,
'on missingTranslation'=>  ['\ backend \ modules \ i18n \ Module','missingTranslation'] 


 'sourcePath'=> Yii :: getAlias('@ base'),
'languages'=>  ['uz','ru'],
'translator'=>  'yii :: t',
'sort'=>  false,
'removeUnused'=> 是的,
'only'=>  [
'* .php',
'ignoreCategories'=>  ['yii'],


  php yii message @common/config / messages /  _base.php 

并且 php yii message 但是它始终将所有消息写入文件:vendor / yiisoft / yii2 / messages。 如何将消息导出到DB? 有人帮忙吗?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douni1396 2018-02-28 15:53

    You need to use the following as per CONSOLE-DOCS there is a ExtendedMessageControler class. This controller extends default MessageController to provide some useful actions:

    • To migrate messages between different message sources run the common like below

      php console/yii message/migrate @common/config/messages/php.php @common/config/messages/db.php

    Which means you should have a file inside the @common/confiog/messages/ folder with the name db.php that will be used to create the message and source_message tables the contents of the file should be

    return \yii\helpers\ArrayHelper::merge(
        require(__DIR__ . '/_base.php'),
            // 'db' output format is for saving messages to database.
            'format' => 'db',
            // Connection component to use. Optional.
            'db' => 'db',
            // Custom source message table. Optional.
            'sourceMessageTable' => '{{%i18n_source_message}}',
            // Custom name for translation message table. Optional.
            'messageTable' => '{{%i18n_message}}',

    and the messages source directory will be determined by the php.php file inside the @common/config/messages directory that contains the following

    return \yii\helpers\ArrayHelper::merge(
        require(__DIR__ . '/_base.php'),
            // 'php' output format is for saving messages to php files.
            'format' => 'php',
            // Root directory containing message translations.
            'messagePath' => Yii::getAlias('@common/messages'),
            // boolean, whether the message file should be overwritten with the merged messages
            'overwrite' => true,

    You just need to run the migration command and the tables will be created and the messages will be exported to the respective tables.

    for more details see the SOURCE for the actionMigrate().

    解决 无用
    打赏 举报

相关推荐 更多相似问题