3

我有这个错误:

捆绑包“AcmeOggyBundle”不存在或未启用。也许您忘记将它添加到 AppKernel.php 文件的 registerBundles() 方法中?

这是我registerBundlesAppKernel.php文件中的功能:

public function registerBundles()
{
    $bundles = array(
        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 Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new JMS\AopBundle\JMSAopBundle(),
        new JMS\DiExtraBundle\JMSDiExtraBundle($this),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
        new Acme\OggyBundle\OggyBundle(),
    );

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

    return $bundles;
}

我不明白...我包含 bundle new Acme\OggyBundle\OggyBundle(),但收到错误消息说我的 bundle 不包括在内!为什么?

日志文件:

[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.response”到监听器“Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse”。[] []
[2013-06-13 10:46:20] event.DEBUG:通知事件“kernel.terminate”到监听器“Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate”。[] []
4

1 回答 1

2

如果您的捆绑包名称是Acme OggyBundle ... 那么您需要注册 ...

// ...
new Acme\OggyBundle\AcmeOggyBundle(), 
// ...

... 代替

new Acme\OggyBundle\OggyBundle(),

AcmeOggyBundle 类必须在文件中...

src/Acme/OggyBundle/AcmeOggyBundle.php

... 带有命名空间Acme\OggyBundle和类名 AcmeOggyBundle

<?php

namespace Acme\OggyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class AcmeOggyBundle extends Bundle
{
}

如果您的包仍未加载...确保src/文件夹中的类正在自动加载

您的 composer.json 必须包含

    "autoload": {
        "psr-0": { "": "src/" }
    }

之后跑...

composer update -o

...为了重新生成由composer生成的vendor/autoload.php 。

于 2013-06-13T06:38:24.437 回答