【问题标题】:[Symfony\Component\Config\Exception\FileLoaderLoadException]Cannot load resource "@UserBundle/Controller/"[Symfony\Component\Config\Exception\FileLoaderLoadException]无法加载资源“@UserBundle/Controller/”
【发布时间】:2017-01-22 10:14:10
【问题描述】:

我的 Symfony 项目在 prod 中遇到了很多问题。我的最后一个问题是当我尝试清理缓存时:

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

控制台返回我:

[Symfony\Component\Config\Exception\FileLoaderLoadException]
无法加载资源“@UserBundle/Controller/”。确保 “UserBundle”捆绑包已正确注册并加载到 应用程序内核类。如果捆绑包已注册,请确保 捆绑路径“@UserBundle/Controller/”不为空。

我认为我有正确的 AppKernel 和 routing.yml: 应用内核:

<?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

我认为这个问题在我的网站上给了我一个索引。

【问题讨论】:

  • 在编写yml 语法时要小心。来自routing.ymluser: 应该与home:NelmioApiDocBundle: 处于同一级别。
  • 对不起,当我复制和粘贴时,我的 yml 文件做得不好。 @DanCostinel
  • 发布UserBundle的目录结构。

标签: php symfony


【解决方案1】:

我发现错误,是 SensioFrameworkExtraBundle 声明错误:

  <?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');
        }
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-27
    • 2018-03-25
    • 2019-08-02
    • 2021-05-28
    • 2020-05-15
    • 1970-01-01
    相关资源
    最近更新 更多