Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 bundle not registering

I created a new bundle with app/console. Trying to get a simple hello printed, so I can move on. I autoloaded the namespace, registered the bundle, created a page but Symfony detects an exception:

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

But I have already done that.

The log shows:

[2011-06-08 23:41:56] request.CRITICAL: InvalidArgumentException: Bundle "PageBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() function of your AppKernel.php file? (uncaught exception) at /Applications/MAMP/htdocs/Symfony/app/bootstrap.php.cache line 634 

I also cleared the cached dev folder. Can anyone help me figure out whats wrong. I have done this before, it's the first time I'm having this problem. Something to do with bootstrap.php.cache

Thanks! Appreciate all the help.

CODE:

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\DoctrineBundle\DoctrineBundle(),
        new Symfony\Bundle\AsseticBundle\AsseticBundle(),
        new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
        new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'))) {
        $bundles[] = new Webmuch\PageBundle\WebmuchPageBundle();
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
        $bundles[] = new Symfony\Bundle\WebConfiguratorBundle\SymfonyWebConfiguratorBundle();
    }

    return $bundles;
}

The bundle also shows as an active bundle in the profiler.

like image 791
Aayush Avatar asked Jun 08 '11 19:06

Aayush


Video Answer


2 Answers

It doesn't look like a problem with the bootstrap cache (line 634 points to the Kernel::getBundles() method, which is what's throwing the exception), but just in case, there's a script that will rebuild it: bin\build_bootstrap.php. The cache exists to reduce the number of require()s that Symfony would need to make to load the core Symfony classes, and as long as you're using one of the betas, it's unlikely that there's anything actually wrong in there.

It sounds like it might be a naming problem: your error complains about the lack of a PageBundle, but according to your kernel, the bundle ought to be called WebmuchPageBundle. Have you referenced it properly in your routing_dev.yml? An example routing config would be:

page:
    resource: "@WebmuchPageBundle/Controller/DefaultController.php"
    type:     annotation

Because you've only defined that bundle for the dev & test environments, you should use routing_dev.yml and not routing.yml.

Next, check that the bundle class is named correctly. You should have a file in the root of your bundle (e.g. src/Webmuch/PageBundle/WebmuchPageBundle.php) with the following content:

namespace Webmuch\PageBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;

class WebmuchPageBundle extends Bundle
{
}

Oh and obviously check that the web server's user can read your bundle directory. I think that throws a different error, but it's worth checking!

like image 64
inanimatt Avatar answered Oct 10 '22 12:10

inanimatt


I had this error before. Check your routings! Probably somewhere you have lines like this:

webmuch_page_hello_world:
    pattern:   /hello
    defaults: { _controller: PageBundle:Default:hello }

There "PageBundle" is not right. You should use "WebmuchPageBundle". So use it like this: WebmuchPageBundle:Default:hello

like image 3
Jumi Avatar answered Oct 10 '22 13:10

Jumi