Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将Yiic message命令与CDbMessageSource一起使用_Yii - Fatal编程技术网

如何将Yiic message命令与CDbMessageSource一起使用

如何将Yiic message命令与CDbMessageSource一起使用,yii,Yii,我曾经使用过CPhpMessageSource,但我想尝试一下CDbMessageSource,我只是想改变一下 'components' => array( 'message' => array( // 'class' => 'CPhpMessageSource', 'class' => 'CDbMessageSource', ), 但当我执行Yiic message在数据库中插入翻译数据时

我曾经使用过CPhpMessageSource,但我想尝试一下CDbMessageSource,我只是想改变一下

'components' => array(
        'message' => array(
//            'class' => 'CPhpMessageSource',
            'class' => 'CDbMessageSource',
        ),
但当我执行Yiic message在数据库中插入翻译数据时,它仍然会在protected/messages/“files.php中生成文件

我一定错过了一点

我遵循这一点

即使Yii有一个数据库翻译的“阅读器”,但它没有“编写器”。我通常会编写一些代码,使用生成的翻译文件填充表

您还可以为Yii编写派生的“message”命令,并使用该命令直接插入数据库,这并不需要太多工作:

<?php

Yii::import('system.cli.commands.MessageCommand', TRUE);

class DbMessageCommand extends MessageCommand
{
   protected function generateMessageFile($messages,$fileName,$overwrite,$removeOld,$sort)
   {
      if (preg_match('@/(..)/([^\\/:"*?<>|]+?)\.php$@i', $fileName, $matches))
      {
         $language = $matches[1];
         $category = $matches[2];

         foreach ($messages as $message)
         {
            // $message contains the string, $category has the category and $language is the current language
            // Add to your DB here
         }
      }
   }
}