简体   繁体   中英

[Symfony\Component\Config\Exception\FileLoaderLoadException]Cannot load resource “@UserBundle/Controller/”

I am having a lot of problems with my Symfony project in prod. My last problem is when I try to clean cache:

php bin/console cache:clear --env=prod --no-debug

console return me:

[Symfony\\Component\\Config\\Exception\\FileLoaderLoadException]
Cannot load resource "@UserBundle/Controller/". Make sure the "UserBundle" bundle is correctly registered and loaded in the application kernel class. If the bundle is registered, make sure the bundle path "@UserBundle/Control ler/" is not empty.

I think I have right AppKernel and routing.yml: AppKernel:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

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 Nelmio\ApiDocBundle\NelmioApiDocBundle(),
            new HomeBundle\HomeBundle(),
            new UserBundle\UserBundle(),
        ];

        if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {
            $bundles[] = new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle();
            $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;
    }

    public function getRootDir()
    {
        return __DIR__;
    }

    public function getCacheDir()
    {
        return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
    }

    public function getLogDir()
    {
        return dirname(__DIR__).'/var/logs';
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
    }
}

Routing.yml:

user:
    resource: "@UserBundle/Controller"
    type:     annotation
    prefix:   /user

home:
    resource: "@HomeBundle/Controller"
    type:     annotation
    prefix:   /

NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

I think that problem is giving me a index of in my website.

I found the error, was the SensioFrameworkExtraBundle was bad declared:

  <?php

    use Symfony\Component\HttpKernel\Kernel;
    use Symfony\Component\Config\Loader\LoaderInterface;

    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 Nelmio\ApiDocBundle\NelmioApiDocBundle(),
                //this bundle must be here
                new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(); 
                new HomeBundle\HomeBundle(),
                new UserBundle\UserBundle(),
            ];

            if (in_array($this->getEnvironment(), ['dev', 'test'], true))
                //remove SensioFrameworkbundle
                $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;
        }

        public function getRootDir()
        {
            return __DIR__;
        }

        public function getCacheDir()
        {
            return dirname(__DIR__).'/var/cache/'.$this->getEnvironment();
        }

        public function getLogDir()
        {
            return dirname(__DIR__).'/var/logs';
        }

        public function registerContainerConfiguration(LoaderInterface $loader)
        {
            $loader->load($this->getRootDir().'/config/config_'.$this->getEnvironment().'.yml');
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM