Invictus
Invictus

Reputation: 250

Symfony 4.0 doesn't work

To the point:
- I created new project on symfony 4.0: composer create-project symfony/skeleton sf4
- Welcome page is working
- I wanted to create my first page with https://symfony.com/doc/current/page_creation.html and I did exactly what they say: create controller and route
- Welcome page changed status to: No route found for "GET /" <-Solved
- new page path can't find file - Error 404

What am I doing wrong? That is silly

~src/Controller/SecurityController.php

<?php
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;

class SecurityController {
    public function logowanie() {
        return new Response(
            '<html><body>Logowanie</body></html>'
        );
    }
}


~config/routes.yaml

index:
    path: /
    controller: App\Controller\MainController::index

logowanie:
    path: /logowanie
    controller: App\Controller\SecurityController::logowanie

EDIT:
Home page works - thanks @Cerad

Upvotes: 1

Views: 5391

Answers (3)

juanitourquiza
juanitourquiza

Reputation: 2194

This code is the solution in Symfony 4.1:

composer require symfony/apache-pack

After the link can be used:

http://localhost/(name-project)/public/index.php/(name of controller)

Upvotes: 1

MatMouth
MatMouth

Reputation: 943

I had the same problem. Homepage was working, but any other urls generate a 404, served by apache, and not logged in symfony.

My mistake was the missconfiguration of the virtualhost. As there is no longer .htaccess in the public directory, you have to configure redirection & rewrite in your virtualhost. Here is the documentation: https://symfony.com/doc/master/setup/web_server_configuration.html

Upvotes: 6

yceruto
yceruto

Reputation: 9575

enter image description here

There's no real route nor controller with welcome template on Symfony 4 apps, it's just a trick to improve the user's first experience.

The welcome response work only for root path / and upon added a route or installed a bundle that adds one (e.g. TwigBundle) this response disappears, as well as if debug mode has been deactivated.

Even, the status code of this response still is 404 (NOT FOUND).

Upvotes: 1

Related Questions