I have created a new Symfony 3.4 project using:
composer create-project symfony/skeleton my-project
After that I added the following components:
composer require twig
composer require annotations
composer require maker
And created a Controller:
php bin/console make:controller
I added an action with a route "legal". Here is the DefaultController:
<?php
namespace App\Controller;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class DefaultController extends Controller
{
/**
* @Route("/", name="homepage")
*/
public function index()
{
return $this->render('index.html.twig', [
'controller_name' => 'DefaultController',
]);
}
/**
* @Route("/legal", name="legal")
*/
public function legal()
{
return $this->render('legal.html.twig', []);
}
}
File config/routes.yaml:
#index:
# path: /
# defaults: { _controller: 'App\Controller\DefaultController::index' }
And config/routes/annotations.yaml:
controllers:
resource: ../../src/Controller/
type: annotation
When I access the homepage, no problem, the page is showing. But when I try the /legal page, I have a 404 :
Not Found - The requested URL /legal was not found on this server.
php bin/console debug:router
shows the expected:
------------------ -------- -------- ------ --------------------------
Name Method Scheme Host Path
------------------ -------- -------- ------ --------------------------
homepage ANY ANY ANY /
legal ANY ANY ANY /legal
_twig_error_test ANY ANY ANY /_error/{code}.{_format}
------------------ -------- -------- ------ --------------------------
I cleared the cache, with the console command and by removing the content of the var/cache directory. But still the 404.
I'm new to 3.4. Any ideas ? Thanks...
/
route work ? – Vertigo/
route works. I figured out that I had forgotten the.htaccess
, which is not created automatically by Symfony/Flex (see my answer). – Postal