[英]Trying to install SyliusProductBundle on Symfony 5.4: LocaleNotFoundException
我正在嘗試在 Symfony 5.4 上安裝獨立的SyliusProductBundle
,但不斷收到LocaleNotFoundException
: "Locale could not be found!"
從干凈的 Symfony 5.4 安裝 ( --webapp
) 開始,然后按照此處的(過時的)文檔操作: https://docs.sylius.com/en/1.12/components_and_bundles/bundles/SyliusProductBundle/installation.html
安裝包:
composer require sylius/product-bundle -w
手動將底部 3 行添加到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
:
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
表中手動添加語言環境,如此處所述,但這似乎不起作用: https://github.com/Sylius/Sylius/issues/8976#issuecomment-468678369
還嘗試將sylius_locale
表重命名為sylius_channel_locales
(根據該問題的最后評論)並向其添加語言環境,但這也不起作用。
如何設置語言環境?
在此處的問題中找到答案: https://github.com/Sylius/Sylius/issues/8452和https://github.com/Sylius/Sylius/issues/7853
解決方法是將src
目錄下的Kernel.php
文件替換成如下內容:
<?php
namespace App;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
class Kernel extends BaseKernel implements CompilerPassInterface
{
use MicroKernelTrait;
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition("sylius.context.locale.composite");
$definition->setDecoratedService(null);
}
}
您不必將語言環境添加到數據庫中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.