2
votes

i am having an issue with AppKernel and the bundle detector.

I am working in 2.5.6

Indeed, i have this error: Bundle "mainBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?

But here is my AppKernel.php:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    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 theia\mainBundle\theiamainBundle(),
        );

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

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }
}

I am having this issue when i try to link the routing.yml of the so called bundle with the app/config/routing.yml or routing_dev.yml.

To do this i add this in the app/.../routing.yml

t:
    resource: "@theiamainBundle/Resources/config/routing.yml"
    prefix:   /

Error Trace:

in kernel.root_dir/bootstrap.php.cache at line 2359 - public function getBundle($name, $first = true) { if (!isset($this->bundleMap[$name])) { throw new \InvalidArgumentException(sprintf('Bundle "%s" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your %s.php file?', $name, get_class($this))); } if (true === $first) { return $this->bundleMap[$name][0]; at Kernel ->getBundle ('mainBundle', false) in kernel.root_dir/cache/dev/classes.php at line 2332 + at ControllerNameParser ->parse ('mainBundle:security:login') in kernel.root_dir/cache/dev/classes.php at line 2384 + at ControllerResolver ->createController ('mainBundle:security:login') in kernel.root_dir/cache/dev/classes.php at line 2047 + at ControllerResolver ->getController (object(Request)) in /opt/lampp/htdocs/my_projects/Symphony_projects/test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/TraceableControllerResolver.php at line 46 + at TraceableControllerResolver ->getController (object(Request)) in kernel.root_dir/bootstrap.php.cache at line 2969 + at HttpKernel ->handleRaw (object(Request), '1') in kernel.root_dir/bootstrap.php.cache at line 2938 + at HttpKernel ->handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 3087 + at ContainerAwareHttpKernel ->handle (object(Request), '1', true) in kernel.root_dir/bootstrap.php.cache at line 2337 + at Kernel ->handle (object(Request)) in /opt/lampp/htdocs/my_projects/Symphony_projects/test/web/app_dev.php at line 28

here are the Logs trace

INFO - Matched route "login_route" (parameters: "_controller": "mainBundle:security:login", "_route": "login_route") INFO - Populated SecurityContext with an anonymous Token DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelReque st".

CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Bundle "mainBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file?" at /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 2359

DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ErrorsLoggerListener::injectLogger". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController". DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".

Here are the Stack Trace:

[1] InvalidArgumentException: Bundle "mainBundle" does not exist or it is not enabled. Maybe you forgot to add it in the registerBundles() method of your AppKernel.php file? at n/a in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 2359

at Symfony\Component\HttpKernel\Kernel->getBundle('mainBundle', false)
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/cache/dev/classes.php line 2332

at Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser->parse('mainBundle:security:login')
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/cache/dev/classes.php line 2384

at Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver->createController('mainBundle:security:login')
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/cache/dev/classes.php line 2047

at Symfony\Component\HttpKernel\Controller\ControllerResolver->getController(object(Request))
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Controller/TraceableControllerResolver.php line 46

at Symfony\Component\HttpKernel\Controller\TraceableControllerResolver->getController(object(Request))
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 2969

at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), '1')
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 2938

at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), '1', true)
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 3087

at Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel->handle(object(Request), '1', true)
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/app/bootstrap.php.cache line 2337

at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
    in /opt/lampp/htdocs/my_projects/Symphony_projects/test/web/app_dev.php line 28

Do you know were it could come from? Do you need any more files in order to help me?

1
Everything looks right. Did you use the command for generating a bundle or did you make the file structure yourself? symfony.com/doc/current/bundles/SensioGeneratorBundle/commands/… also, depending on your environment you may need to flush the cache. php app/console cache:clear --env=[prod/dev] put either --env=prod or --env=dev at the end depending on which one you're in. You can change you environment by modifying the htaccess in the web folder to point to app.php or app_dev.php. Many code changes in prod won't work until the cache is flushed.Squeegy
I did created the Bundle with the command. I tried to use the specification after the cache clear but changes nothing :/ I forgot to say that i am in 2.5.6MrBouh
Could you post the full error and trace? Maybe the error is occurring somewhere else. Because I'm not seeing any immediate glaring issues, but this is just a tiny slice of the entire framework.Squeegy

1 Answers

0
votes

Your routes seems to have references to a "mainBundle" when specifying the controller, which should be "theiamainBundle":

Matched route "login_route" (parameters: "_controller": "mainBundle:security:login", "_route": "login_route")