Yii2 - strpos(): 第 111 行 PhpMessageSource.php 中的空针

Yii2 - strpos(): Empty needle in PhpMessageSource.php on line 111

请在下面找到我从 apache 错误日志粘贴的堆栈跟踪。

An Error occurred while handling another error:\nyii\web\HeadersAlreadySentException: Headers already sent. in /var/www/html/staging_v2/vendor/yiisoft/yii2/web/Response.php:373\nStack trace:\n#0 
/var/www/html/staging_v2/vendor/yiisoft/yii2/web/Response.php(346): yii\web\Response->sendHeaders()\n#1 
/var/www/html/staging_v2/vendor/yiisoft/yii2/web/ErrorHandler.php(136): yii\web\Response->send()\n#2 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/ErrorHandler.php(135): yii\web\ErrorHandler->renderException(Object(yii\base\ErrorException))\n#3 
[internal function]: yii\base\ErrorHandler->handleException(Object(yii\base\ErrorException))\n#4 

{main}\nPrevious exception:\nyii\base\ErrorException: strpos(): Empty needle in /var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/PhpMessageSource.php:111\nStack trace:\n#0 
[internal function]: yii\base\ErrorHandler->handleError(2, 'strpos(): Empty...', '/var/www/html/s...', 111, Array)\n#1 
/var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/PhpMessageSource.php(111): strpos('en-US', '')\n#2 
/var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/PhpMessageSource.php(78): yii\i18n\PhpMessageSource->loadFallbackMessages('yii', '', NULL, '/var/www/html/s...')\n#3 /var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/MessageSource.php(107): yii\i18n\PhpMessageSource->loadMessages('yii', NULL)\n#4 
/var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/MessageSource.php(87): yii\i18n\MessageSource->translateMessage('yii', '{attribute} can...', NULL)\n#5 
/var/www/html/staging_v2/vendor/yiisoft/yii2/i18n/I18N.php(90): yii\i18n\MessageSource->translate('yii', '{attribute} can...', NULL)\n#6 
/var/www/html/staging_v2/vendor/yiisoft/yii2/BaseYii.php(538): yii\i18n\I18N->translate('yii', '{attribute} can...', Array, NULL)\n#7 
/var/www/html/staging_v2/vendor/yiisoft/yii2/validators/RequiredValidator.php(62): yii\BaseYii::t('yii', '{attribute} can...')\n#8 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/BaseObject.php(109): yii\validators\RequiredValidator->init()\n#9 
[internal function]: yii\base\BaseObject->__construct(Array)\n#10 
/var/www/html/staging_v2/vendor/yiisoft/yii2/di/Container.php(420): ReflectionClass->newInstanceArgs(Array)\n#11 
/var/www/html/staging_v2/vendor/yiisoft/yii2/di/Container.php(171): yii\di\Container->build('yii\\validators\\...', Array, Array)\n#12 
/var/www/html/staging_v2/vendor/yiisoft/yii2/BaseYii.php(365): yii\di\Container->get('yii\\validators\\...', Array, Array)\n#13 
/var/www/html/staging_v2/vendor/yiisoft/yii2/validators/Validator.php(231): yii\BaseYii::createObject(Array)\n#14 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(469): yii\validators\Validator::createValidator('yii\\validators\\...', Object(frontend\models\ContactForm), Array, Array)\n#15 /var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(421): yii\base\Model->createValidators()\n#16 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(190): yii\base\Model->getValidators()\n#17 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(817): yii\base\Model->scenarios()\n#18 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(435): yii\base\Model->activeAttributes()\n#19 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Model.php(495): yii\base\Model->getActiveValidators('name')\n#20 
/var/www/html/staging_v2/vendor/yiisoft/yii2/widgets/ActiveField.php(929): yii\base\Model->isAttributeRequired('name')\n#21 
/var/www/html/staging_v2/vendor/yiisoft/yii2/widgets/ActiveField.php(405): yii\widgets\ActiveField->addAriaAttributes(Array)\n#22 
/var/www/html/staging_v2/frontend/views/site/index.php(143): yii\widgets\ActiveField->textInput(Array)\n#23 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/View.php(348): require('/var/www/html/s...')\n#24 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/View.php(257): yii\base\View->renderPhpFile('/var/www/html/s...', Array)\n#25 
/var/www/html/staging_v2/vendor/yiisoft/yii2/web/View.php(213): yii\base\View->renderFile('/var/www/html/s...', Array, Object(frontend\controllers\SiteController))\n#26 /var/www/html/staging_v2/vendor/yiisoft/yii2/web/Controller.php(53): yii\web\View->renderAjax('index', Array, Object(frontend\controllers\SiteController))\n#27 /var/www/html/staging_v2/frontend/controllers/SiteController.php(555): yii\web\Controller->renderAjax('index', Array)\n#28 
[internal function]: frontend\controllers\SiteController->actionIndex()\n#29 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)\n#30 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Controller.php(181): yii\base\InlineAction->runWithParams(Array)\n#31 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Module.php(534): yii\base\Controller->runAction('index', Array)\n#32 
/var/www/html/staging_v2/vendor/yiisoft/yii2/web/Application.php(104): yii\base\Module->runAction('site/index', Array)\n#33 
/var/www/html/staging_v2/vendor/yiisoft/yii2/base/Application.php(392): yii\web\Application->handleRequest(Object(yii\web\Request))\n#34 
/var/www/html/staging_v2/frontend/web/index.php(0): yii\base\Application->run()\n#35 

您可以在此处找到问题:https://staging-v2.storna.app 管理门户工作 https://staging-v2.storna.app/admin API 也有效

只有着陆页有问题..它之前工作正常。

可能是什么问题?

日志中只有 2 个问题。其中 1 个是警告,另一个只是 php7 通知。所以我怀疑是不是因为这个。

您似乎使用的是 2.0.40 版本,这已被报告 here。似乎问题只存在于 PHP 版本 7.1 - 7.4 上,因为 PHP 8.0 似乎已成功通过,原因是

Looks like the previous versions were resilient to language being set to null

您可以将 composer.json 中的 minimum-stability 设置从 stable 更改为 dev,以及 运行 composer update 以更新您的yii 框架到 dev-master。

或者您可以仅从此 commit

手动更新这些文件

我会使用第二个选项,因为第一个选项也会更新所有包。