How to include bundle correctly?

I have this error:

Bundle "AcmeOggyBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?

Here is my registerBundles function in AppKernel.php file:

public function registerBundles()
{
    $bundles = array(
        new SymfonyBundleFrameworkBundleFrameworkBundle(),
        new SymfonyBundleSecurityBundleSecurityBundle(),
        new SymfonyBundleTwigBundleTwigBundle(),
        new SymfonyBundleMonologBundleMonologBundle(),
        new SymfonyBundleSwiftmailerBundleSwiftmailerBundle(),
        new SymfonyBundleAsseticBundleAsseticBundle(),
        new DoctrineBundleDoctrineBundleDoctrineBundle(),
        new SensioBundleFrameworkExtraBundleSensioFrameworkExtraBundle(),
        new JMSAopBundleJMSAopBundle(),
        new JMSDiExtraBundleJMSDiExtraBundle($this),
        new JMSSecurityExtraBundleJMSSecurityExtraBundle(),
        new AcmeOggyBundleOggyBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new AcmeDemoBundleAcmeDemoBundle();
        $bundles[] = new SymfonyBundleWebProfilerBundleWebProfilerBundle();
        $bundles[] = new SensioBundleDistributionBundleSensioDistributionBundle();
        $bundles[] = new SensioBundleGeneratorBundleSensioGeneratorBundle();
    }

    return $bundles;
}

I don't understand... I include bundle new AcmeOggyBundleOggyBundle() , but get an error saying my bundle is not included! Why?

Log file:

[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyBridgeMonologHandlerFirePHPHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyBridgeMonologHandlerChromePhpHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SensioBundleFrameworkExtraBundleEventListenerCacheListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentHttpKernelEventListenerResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentHttpKernelEventListenerLocaleListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentHttpKernelFragmentFragmentHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentSecurityHttpRememberMeResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentHttpKernelEventListenerProfilerListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyBundleWebProfilerBundleEventListenerWebDebugToolbarListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "SymfonyComponentHttpKernelEventListenerStreamedResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.terminate" to listener "SymfonyBundleSwiftmailerBundleEventListenerEmailSenderListener::onKernelTerminate". [] []

If your bundle's name is Acme OggyBundle ... then you need to register ...

// ...
new AcmeOggyBundleAcmeOggyBundle(), 
// ...

... instead of

new AcmeOggyBundleOggyBundle(),

The AcmeOggyBundle class has to be in the file ...

src/Acme/OggyBundle/AcmeOggyBundle.php

... with namespace AcmeOggyBundle and classname AcmeOggyBundle

<?php

namespace AcmeOggyBundle;

use SymfonyComponentHttpKernelBundleBundle;

class AcmeOggyBundle extends Bundle
{
}

and if your bundle is still not loaded ... make sure the classes in the src/ folder are being autoloaded .

Your composer.json has to contain

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

Afterwards run ...

composer update -o

... in order to regenerate the vendor/autoload.php which is generated by composer.

链接地址: http://www.djcxy.com/p/53996.html

上一篇: 试图在类(Symfony)上调​​用方法“getDoctrine”

下一篇: 如何正确包含包?