JonnyD
JonnyD

Reputation: 73

"Bundle "App" does not exist or it is not enabled

I'm getting this error when GETing{{url}}/api/user/me:

An exception has been thrown during the rendering of a template ("Bundle >"App" does not exist or it is not enabled. Maybe you forgot to add it in the >registerBundles() method of your App\Kernel.php file? in @App/Controller/UserController (which is being imported from "....\config/routes.yaml"). Make >sure the "App/Controller/UserController" bundle is correctly registered and >loaded in the application kernel class. If the bundle is registered, make >sure the bundle path "@App/Controller/UserController" is not empty.").

I'm using FOSRestBundle and FOSOauthBundle.

routes.yml

app_api:
  resource: "@App/Controller/UserController"
  type:     annotation

bundles.php

<?php

return [
    Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
    Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle::class => ['all' => true],
    Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
    Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
    Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
    Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
    Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
    Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
    Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
    Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
    Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
    Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
    Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
    Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
    Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
    FOS\OAuthServerBundle\FOSOAuthServerBundle::class => ['all' => true],
    FOS\RestBundle\FOSRestBundle::class => ['all' => true],
    JMS\SerializerBundle\JMSSerializerBundle::class => ['all' => true],
    Nelmio\ApiDocBundle\NelmioApiDocBundle::class => ['all' => true],
    FOS\UserBundle\FOSUserBundle::class => ['all' => true]
];

UserController

<?php

namespace App\Controller;

use App\Entity\User;
use App\Service\UserService;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use FOS\RestBundle\View\View;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use FOS\RestBundle\Controller\Annotations\RouteResource;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

/**
 * @RouteResource("User")
 */
class UserController extends AbstractFOSRestController implements ClassResourceInterface
{
    /**
     * @var TokenStorageInterface
     */
    private $tokenStorage;

    /**
     * @param TokenStorageInterface $tokenStorage
     */
    public function __construct(TokenStorageInterface $tokenStorage)
    {
        $this->tokenStorage = $tokenStorage;
    }

    /**=
     * @Route("/api/user/me")
     * @Method("GET")
     *
     * @return User|string
     */
    public function getMeAction()
    {
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');

        $loggedInUser = $this->tokenStorage->getToken()->getUser();

        return new Response($loggedInUser);
    }

composer.json

...
"autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
...

Directory

Upvotes: 1

Views: 5364

Answers (1)

emarref
emarref

Reputation: 1311

The @App/... notation with the "at" symbol is used purely to resolve the location of a bundle.

You are trying to resolve the location of your project source files which do not live in a bundle.

In routes.yml try this instead:

app_api:
  resource: "../src/Controller/*"
  type:     annotation

Upvotes: 2

Related Questions