Symfony2: How to enable autocompletion for annotations in PHPStorm?

Viewed 4749

Following this simple code:

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;


class TestController extends Controller
{
    /**
     * @param $value
     * @return Response
     */
    public function indexAction($value)
    {
        return new Response('Hello:' . $value);
    }
}

Is any possibility to have code completion when I would like to add @Route in phpDoc? When I type @Route it should show code completion and automatic add "use" statement? I watched a symfony tutorial (I'm beginner) and in this video PHPStrom showed code completion and automatic added "use" statement... I installed symfony plugin and other things and code completions works.

2 Answers

I don't have a high enough reputation to comment, so I'll add this as an additonal answer. If you are following some sort of guide or video tutorial, and are unable to get the @Assert to autocomplete, this is because Validator has not been imported into the file you're editing.

add this to your use statements: use Symfony\Component\Validator\Constraints as Assert;

The course I was following didn't mention this, and I ended up finding it on some random website.

For some reason php storm doesn't give you the option to import it once you've typed it out, like it usually does.

Related