在 Yii 2.0 中报错:Exception ‘yii\base\InvalidConfigException’ with message ‘Unable to locate message source for category ‘error’.’
1、在 Yii 2.0 中报错:Exception ‘yii\base\InvalidConfigException’ with message ‘Unable to locate message source for category ‘error’.’。如图1
PS E:\wwwroot\ccp_api_dev_new> ./yii callback/index --appconfig=ccp/config/console.php Exception 'yii\base\InvalidConfigException' with message 'Unable to locate message source for category 'error'.' in E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\i18n\I18N.php:201 Stack trace: #0 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\i18n\I18N.php(89): yii\i18n\I18N->getMessageSource('error') #1 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\BaseYii.php(538): yii\i18n\I18N->translate('error', '205064', Array, 'zh-CN') #2 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(261): yii\BaseYii::t('error', '205064') #3 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(274): common\services\ChannelAppTaskService::findModelByUuid('888') #4 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(584): common\services\ChannelAppTaskService::findModelPublishByUuid('888') #5 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(16): common\services\ChannelAppTaskService::crontabVttHandler(Array) #6 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(62): ccp\commands\CallbackController->start() #7 [internal function]: ccp\commands\CallbackController->actionIndex() #8 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) #9 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array) #10 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Controller.php(184): yii\base\Controller->runAction('index', Array) #11 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Module.php(534): yii\console\Controller->runAction('index', Array) #12 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(181): yii\base\Module->runAction('callback/index', Array) #13 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(148): yii\console\Application->runAction('callback/index', Array) #14 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request)) #15 E:\wwwroot\ccp_api_dev_new\yii(23): yii\base\Application->run() #16 {main}
2、编辑 ccp/config/console.php,添加组件:i18n
'components' => [ 'i18n' => [ 'translations' => [ '*' => [ 'class' => 'yii\i18n\PhpMessageSource', 'forceTranslation' => true, 'basePath' => '@app/messages', 'fileMap' => [ 'application' => 'application.php', 'error' => 'error.php', 'success' => 'success.php', ], ], ], ], ]
3、再次运行命令行,报错:Exception ‘yii\web\NotFoundHttpException’ with message ‘205064’。如图2
PS E:\wwwroot\ccp_api_dev_new> ./yii callback/index --appconfig=ccp/config/console.php Exception 'yii\web\NotFoundHttpException' with message '205064' in E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php:261 Stack trace: #0 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(274): common\services\ChannelAppTaskService::findModelByUuid('888') #1 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(584): common\services\ChannelAppTaskService::findModelPublishByUuid('888') #2 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(16): common\services\ChannelAppTaskService::crontabVttHandler(Array) #3 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(62): ccp\commands\CallbackController->start() #4 [internal function]: ccp\commands\CallbackController->actionIndex() #5 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) #6 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array) #7 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Controller.php(184): yii\base\Controller->runAction('index', Array) #8 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Module.php(534): yii\console\Controller->runAction('index', Array) #9 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(181): yii\base\Module->runAction('callback/index', Array) #10 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(148): yii\console\Application->runAction('callback/index', Array) #11 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request)) #12 E:\wwwroot\ccp_api_dev_new\yii(23): yii\base\Application->run() #13 {main}
4、新建目录,/ccp/messages。文件 /ccp/messages/zh-CN/error.php 的内容如下。如图3
<?php $commonMessages = require __DIR__ . '/../../../common/messages/zh-CN/error.php'; $messages = [ ]; return $commonMessages + $messages;
5、再次运行命令行,运行结果符合预期,未再报错。如图4
PS E:\wwwroot\ccp_api_dev_new> ./yii callback/index --appconfig=ccp/config/console.php Exception 'yii\web\NotFoundHttpException' with message '渠道的应用的任务UUID:888,不存在' in E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php:261 Stack trace: #0 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(274): common\services\ChannelAppTaskService::findModelByUuid('888') #1 E:\wwwroot\ccp_api_dev_new\common\services\ChannelAppTaskService.php(584): common\services\ChannelAppTaskService::findModelPublishByUuid('888') #2 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(16): common\services\ChannelAppTaskService::crontabVttHandler(Array) #3 E:\wwwroot\ccp_api_dev_new\ccp\commands\CallbackController.php(62): ccp\commands\CallbackController->start() #4 [internal function]: ccp\commands\CallbackController->actionIndex() #5 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\InlineAction.php(57): call_user_func_array(Array, Array) #6 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Controller.php(181): yii\base\InlineAction->runWithParams(Array) #7 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Controller.php(184): yii\base\Controller->runAction('index', Array) #8 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Module.php(534): yii\console\Controller->runAction('index', Array) #9 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(181): yii\base\Module->runAction('callback/index', Array) #10 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\console\Application.php(148): yii\console\Application->runAction('callback/index', Array) #11 E:\wwwroot\ccp_api_dev_new\vendor\yiisoft\yii2\base\Application.php(392): yii\console\Application->handleRequest(Object(yii\console\Request)) #12 E:\wwwroot\ccp_api_dev_new\yii(23): yii\base\Application->run() #13 {main}
近期评论