Php AppKernel捆绑包未注册

Php AppKernel捆绑包未注册,php,symfony,Php,Symfony,给定的是我的appKernel类,同时注册它用来生成类的bundle new FOS\RestBundle\FOSRestBundle(), new JMS\SerializerBundle\JMSSerializerBundle(), new Nelmio\CorsBundle\NelmioCorsBundle(), 但我使用以下命令从composer生成它们 composer require friendsofsymfony/rest-bundle composer require jms

给定的是我的appKernel类,同时注册它用来生成类的bundle

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未注册

运行命令并清除缓存:

php bin/console cache:clear

还可以在top AppKernel.php中添加use类,在一个配置文件中还会对它们进行一些配置。通常在
app/config/config.yml
中。即使它们都是默认的,它们也需要通过配置中的条目(yml或xml)完全启用

您可以使用命令
bin/console debug:config JMSSerializerBundle
查看示例(并完成所有默认设置),根据需要替换捆绑包名称


其他的有,也有类似的。

运行命令:composer update