修复Symfony 5错误:during the rendering of a template “Unimplemented date character “Y” in format “MMMM dd Y”

2021年11月29日23:48:32 发表评论 691 次浏览

了解在 Twig 中尝试使用自定义日期格式时如何轻松解决此问题。

修复Symfony 5错误:during the rendering of a template
Unimplemented date character解决办法

在使用 PHP 7.4.8 几周后,我在 Xampp 环境中转移到 PHP 7.4.11,这迫使我安装新版本并将所有项目从旧目录移动到新目录,但是,我没有在新版本中复制相同的 php.ini 配置文件,因为我认为它会按预期工作而不会那么麻烦。嗯,它没有😆。我开始项目的时候,首页出现如下异常:

An exception has been thrown during the rendering of a template ("Unimplemented date character "Y" in the format "MMMM dd Y". Please install the "intl" extension for full localization capabilities.").

这是在项目上实施 twig/intl-extra 包之后开始发生的。如何修复错误Unimplemented date character?幸运的是,该解决方案在任何环境下都非常简单,因为正如错误描述的那样,你只需要安装/启用 PHP 的 intl 扩展即可。

Xampp for Windows 中的 PHP

Unimplemented date character解决办法:如果你在 Windows 中使用 PHP,你可能会使用 XAMPP。你可以通过修改位于 xampp 中 PHP 目录中的默认配置文件 php.ini 轻松修复此错误:

; c:/xampp/php/php.ini
; Uncomment the intl extension to enable the intl module
extension=intl

取消注释该行(只需删除该行开头的分号)后,该模块现在应该处于活动状态。你只需要重新启动 Apache 和 MySQL 服务,它现在就可以工作了:

修复Symfony 5错误:during the rendering of a template

Ubuntu 中的 PHP

如何修复错误Unimplemented date character?如果你直接在 Ubuntu 服务器上工作,则可以在终端中安装 intl 扩展。首先,更新存储库:

sudo apt-get update

然后,根据服务器的PHP版本,你可以使用以下命令进行安装:

# If you are using PHP 5.6
sudo apt-get install php5.6-intl

# If you are using PHP 7.0
sudo apt-get install php7.0-intl

# If you are using PHP 7.4
sudo apt-get install php7.4-intl

安装模块后,不要忘记重启apache:

sudo service apache2 restart

在这种环境下,问题也应该消失了。

快乐编码❤️!

木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: