最近把Symfony4升级到6,php版本也跟着升到8.2.5,体验了把新版本好处,但发现几个问题。
默认的构建命令,symfony new my_project_directory --version="6.2.*"
,这是一个典型的API项目,也是我创建的类型。在API环境下,生产环境显然是不用任何模板功能的,但因为开发环境需要模板做展示,所以上线时候产生了一个BUG。
当你加入composer.phar require --dev profiler
为dev环境添加调试条的时候,你会发现一个问题,所有基于Profiler的依赖,例如Twig确实在composer.json的dev里。但是,在config/Bundles.php
里却把因为Profiler依赖而加入的Twig模板引擎标记为全环境都需要Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true]
,这里要改成Symfony\Bundle\TwigBundle\TwigBundle::class => ['dev' => true, 'test' => true]
。
但这时候还没有完,config/packages/twig.yaml
也需要删除,否则Symfony启动的时候检查到配置文件会自动调用,而导致报错。顺便把templates
目录删除,这个是Twig默认加入的模板文件。
最后,记得一点,composer install --no-dev --no-ansi --no-interaction --no-progress --classmap-authoritative --no-scripts --prefer-dist
在你的composer安装命令中,千万不要--no-plugins
,这会导致/vendor/autoload_runtime.php
无法生成!