You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在Symfony 5.4安装SyliusProductBundle时遭遇LocaleNotFoundException

Symfony 5.4 安装SyliusProductBundle遇LocaleNotFoundException问题

我在Symfony 5.4环境下尝试独立安装SyliusProductBundle,但始终抛出LocaleNotFoundException: Locale could not be found!错误,操作流程如下:

操作步骤

  1. 通过--webapp选项全新安装Symfony 5.4
  2. 执行Bundle安装命令:
    composer require sylius/product-bundle -w
    
  3. 由于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],
    ];
    
  4. 创建config/config.yml并添加Doctrine扩展配置:
    stof_doctrine_extensions:
        orm:
            default:
                sluggable: true
                timestampable: true
    
  5. 更新数据库结构:
    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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 09:20:38