Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Annotations in Symfony 4

I try to develop with Symfony 4 so I follow the tutorial on symfony.com

I've got an error when I try to access at :

http://localhost:8000/

This is the error :

[Syntax Error] Expected PlainValue, got ''' at position 7 in method App\Controller\HomeController::home() in /Users//Documents/ProjetSymfo4/my-project/config/routes/../../src/Controller/ (which is being imported from "/Users//Documents/ProjetSymfo4/my-project/config/routes/annotations.yaml"). Make sure annotations are installed and enabled.

I already ran

composer require annotations

And it is installed

In composer.json : 

"require": {
    "php": "^7.1.3",
    "ext-iconv": "*",
    "sensio/framework-extra-bundle": "^5.1",

This is my project :

enter image description here

like image 646
N.Jourdan Avatar asked Feb 23 '18 01:02

N.Jourdan


People also ask

What is Symfony annotation?

As you might know, Symfony2 uses annotations for Doctrine mapping information and validation configuration. Of course, it is entirely optional, and the same can be done with XML, YAML, or even PHP. But using annotations is convenient and allows you to define everything in the same file.

What is route in Symfony?

The routing configuration defines which action to run for each incoming URL. It also provides other useful features, like generating SEO-friendly URLs (e.g. /read/intro-to-symfony instead of index.

How does Symfony routing work?

Symfony provides a Routing component which allows us, for a HTTP request/URL, to execute a specific function (also known as "Controller"). Note: Controllers must be a callable, for example: an anonymous function: $controller = function (Request $request) { return new Response() }; .


1 Answers

I found the issue and how to fix it

As you can see on my screen I wrote

/**
* @Route('/')
*/

However to work we have to put " instead of '

/**
* @Route("/")
*/
like image 89
N.Jourdan Avatar answered Sep 27 '22 22:09

N.Jourdan