在Symfony 5.4安装SyliusProductBundle时遭遇LocaleNotFoundException
Symfony 5.4 安装SyliusProductBundle遇LocaleNotFoundException问题
我在Symfony 5.4环境下尝试独立安装SyliusProductBundle,但始终抛出LocaleNotFoundException: Locale could not be found!错误,操作流程如下:
操作步骤
- 通过
--webapp选项全新安装Symfony 5.4 - 执行Bundle安装命令:
composer require sylius/product-bundle -w - 由于Bundle未自动注册,手动在
config/bundles.php中添加以下三行:<?php return [ Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true], Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true], Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true], Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true], Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true], Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true], Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true], Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true], winzou\Bundle\StateMachineBundle\winzouStateMachineBundle::class => ['all' => true], JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true], Bazinga\Bundle\HateoasBundle\BazingaHateoasBundle::class => ['all' => true], FOS\RestBundle\FOSRestBundle::class => ['all' => true], BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true], Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true], Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true], Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true], Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true], Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true], ]; - 创建
config/config.yml并添加Doctrine扩展配置:stof_doctrine_extensions: orm: default: sluggable: true timestampable: true - 更新数据库结构:
php bin/console doctrine:schema:update --force
触发错误的操作
当执行以下代码获取产品仓库时,抛出LocaleNotFoundException:
$repository = $this->container->get('sylius.repository.product');
已尝试的无效方法
- 手动在
sylius_locale表中添加locale记录 - 将
sylius_locale表重命名为sylius_channel_locales并添加locale记录
请问该如何正确设置locale以解决此问题?
内容的提问来源于stack exchange,提问作者Marleen
相关产品推荐
相关产品推荐

