0

I have just started to learn Symfony. The fact is that I do things and they work but I don't understand what I am doing and that must be the wrong way starting to learn something.

Here is a simple controller:

<?php

namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class HelloController extends Controller
{
    /**
     * @Route("/hello")
     */
    public function helloAction() {
        return $this->render('', array());
    }
}

So in this case when I type

/**
 * @Route("/hello")
 */

my editor automatically adds this line of code:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

What is that doing?

I have learned that namespaces must match the directory path but there is no way I could find that path in my Symfony project. So is it outside of my project? If so, this will be good to know in case I want to upload my project on the web server.

I would appreciate if someone could please explain this "mystery".

2
  • The Route class is inside the vendor folder, where the deps of your project are. Commented Dec 17, 2016 at 13:29
  • You just defined a parameter @Route to your helloAction(). To work properly, it need the class Route located in Sensio\Bundle\FrameworkExtraBundle\Configuration. This is why it was added. Commented Dec 17, 2016 at 13:54

1 Answer 1

1

Your IDE just added the dependency to Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;, which is required to use the @Route annotation.

It is placed under the vendor/ directory, which of course you will need to upload along with your sources.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.