The annotation "@Route" was never imported

12,180

You need to check this file:

AppBundle\Controller\FormController.php

It seems you didn't add the namespace:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

Please check it.

Share:
12,180

Related videos on Youtube

M.Bada
Author by

M.Bada

Updated on September 16, 2022

Comments

  • M.Bada
    M.Bada over 1 year

    I am a student and I am very new in symfony and in stackoverflow then sorry if I do some mistakes.

    Here is the error when I try to access to the page:

    [Semantical Error] The annotation "@Route" in method AppBundle\Controller\FormController::newAction() was never imported. Did you maybe forget to add a "use" statement for this annotation? in /home/buddy/Bachelor/RealBachelor/src/AppBundle/Controller/ (which is being imported from "/home/buddy/Bachelor/RealBachelor/app/config/routing.yml"). Make sure annotations are enabled.

    and here is my controller:

    <?php
    
    namespace AppBundle\Controller;
    
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    use Symfony\Bundle\FrameworkBundle\Controller\Controller;
    use Symfony\Component\HttpFoundation\Request;
    
    class SuccessController extends Controller
    {
        /**
         * @Route("/success", name="success")
         */
        public function indexAction(Request $request)
        {
    
    
            $id = "yeah success!!";
    
            return $this->render('default/index.html.twig', [
                'id' => $id,
            ]);
        }
    }
    

    I don't know if is needed but here is my routing config file:

     # bin/config/routing.yml
    fos_user:
        resource: "@FOSUserBundle/Resources/config/routing/all.xml"
    
    app:
        resource: '@AppBundle/Controller/'
        type: annotation
    
    • William-H-M
      William-H-M over 6 years
    • Stephan Vierkant
      Stephan Vierkant over 6 years
      Your error message says FormController, but you code example says SuccessController. Are you sure you're looking at the right file?
  • Nepomuk Pajonk
    Nepomuk Pajonk over 5 years
    In newer Symfony versions, use Symfony\Component\Routing\Annotation\Route instead.
  • Tuhin
    Tuhin over 3 years
    Please add this as a new answer, as I latest Symfony (5.x) will use the Route file mentioned in @NepomukFrädrich