Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,
I was following the instructions on https://symfony.com/doc/5.4/the-fast-track/en/3-zero.html and next pages.

I'm at the step regarding creating a new controller., so I did symfony console make:controller ConferenceController

Then I tried to open https://localhost:8000/conference and saw the "No route found for "GET https://localhost:8000/conference""

The controller looks like this:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class ConferenceController extends AbstractController
{
    #[Route('/conference', name: 'app_conference')]
    public function index(): Response
    {
        return $this->render('conference/index.html.twig', [
            'controller_name' => 'ConferenceController',
        ]);
    }
}

I tried to clear cache and restart server, nothing worked. Finally I found somewhere (not in the book itself, and actually the problem was different): composer require annotations.

This created this file: "config/routes/annotations.yaml" which looks like this:

controllers:
    resource: ../../src/Controller/
    type: annotation
kernel:
    resource: ../../src/Kernel.php
    type: annotation

And... it worked. But why? I mean - Why did I have to do this, and what does 'annotations' from Doctrine have to do with routing in Symfony?

This book was supposed to guide me step by step into the intricacies of Symfony, and yet I got stuck on such a simple step :(

BTW, I know there is a book for 6.2 but I am supposed to learn 5.4. It's not that old AFAIK.

I'm on the verge of madness... this is my second attempt with Symfony, and also my second with the book "The Fast Track,"

You must be logged in to vote

Have a look at https://symfony.com/doc/5.4/routing.html.
Note that depending on PHP7 OR PHP8 you will have a different composer/config.
Since PHP7 is EOL, read the attributes sections.

As for Symfony project references, you can take a look at the Symfony Demo Project. It can help a lot!

Check also SymfonyCast tutorials

Replies: 2 comments · 1 reply

Comment options

Have a look at https://symfony.com/doc/5.4/routing.html.
Note that depending on PHP7 OR PHP8 you will have a different composer/config.
Since PHP7 is EOL, read the attributes sections.

As for Symfony project references, you can take a look at the Symfony Demo Project. It can help a lot!

Check also SymfonyCast tutorials

You must be logged in to vote
0 replies
Answer selected by kpion
Comment options

Thanks @cavasinf !

OK, I will read the docs, and yeah - those SymfonyCasts are a cool source as well.

But - I believe this thing (installing annotations with composer) should be mentioned in the book (since it tells us to use them). I had a strong impression that the book is incomplete, and I'll soon encounter some more weird issues :) I'm a Symfony beginner, that is why for me it wasn't easy to solve it.

Nevertheless - thanks again! These SymfonyCasts look like a very effective way to learn SF.

You must be logged in to vote
1 reply
@cavasinf
Comment options

I believe this thing (installing annotations with composer) should be mentioned in the book

I read that in the doc:

In PHP 7 and earlier versions you can use annotations (via the Doctrine Annotations library), but first you'll need to install the following dependency in your project

For me, this means that you don't need the doctrine/annotations package.
BUT reading below, you do need the `config/routes/annotations.yaml' file/config.

When you run the doctrine/annotations command, it creates the config file for you,
so if you ran the composer require annotations command, this is why it works as it should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.