AppKernel捆绑不是registring

时间:2018-05-07 08:13:14

标签: php symfony

给出的是我的appKernel类,同时注册它们唱歌以生成类

new FOS\RestBundle\FOSRestBundle(),
new JMS\SerializerBundle\JMSSerializerBundle(),
new Nelmio\CorsBundle\NelmioCorsBundle(),

但我使用以下命令从composer

生成它们
composer require friendsofsymfony/rest-bundle
composer require jms/serializer-bundle
composer require nelmio/cors-bundle



class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new AppBundle\AppBundle(),
            new FOS\RestBundle\FOSRestBundle(),
            new JMS\SerializerBundle\JMSSerializerBundle(),
            new Nelmio\CorsBundle\NelmioCorsBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Symfony\Bundle\DebugBundle\DebugBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

在运行我的php代码时,它会给出异常,因为给定的bundle不是寄存器

2 个答案:

答案 0 :(得分:1)

运行命令并清除缓存:

php bin/console cache:clear

还在顶部AppKernel.php

添加使用类

答案 1 :(得分:0)

配置文件中也会有一些配置。通常在app/config/config.yml。即使它们都是默认值,它们也需要通过配置中的该条目完全启用(yml或xml)。

您可以使用命令bin/console debug:config JMSSerializerBundle查看示例(并使用所有默认值完成),并根据需要替换bundle-name。

其他人存在a page of details for JMSSerializer和类似情况。