Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include bundle correctly?

Tags:

symfony

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 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;
}

I don't understand... I include bundle new Acme\OggyBundle\OggyBundle(), 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 "Symfony\Bridge\Monolog\Handler\FirePHPHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bridge\Monolog\Handler\ChromePhpHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\CacheListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\Fragment\FragmentHandler::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\Security\Http\RememberMe\ResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.response" to listener "Symfony\Component\HttpKernel\EventListener\StreamedResponseListener::onKernelResponse". [] []
[2013-06-13 10:46:20] event.DEBUG: Notified event "kernel.terminate" to listener "Symfony\Bundle\SwiftmailerBundle\EventListener\EmailSenderListener::onKernelTerminate". [] []
like image 597
Johny Oggy Avatar asked Jun 19 '26 19:06

Johny Oggy


1 Answers

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

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

... instead of

new Acme\OggyBundle\OggyBundle(),

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

src/Acme/OggyBundle/AcmeOggyBundle.php

... with namespace Acme\OggyBundle and classname AcmeOggyBundle

<?php

namespace Acme\OggyBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

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.

like image 199
Nicolai Fröhlich Avatar answered Jun 23 '26 18:06

Nicolai Fröhlich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!