【发布时间】: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.yml的user:应该与home:和NelmioApiDocBundle:处于同一级别。 -
对不起,当我复制和粘贴时,我的 yml 文件做得不好。 @DanCostinel
-
发布
UserBundle的目录结构。