0

I'm new to Symfony and I'm trying to make a simple web page, afterinstalling docker, php 8.3 and composer, I downloaded a Symfony image (v5.4.20) and added doctrine to it

Now, both the database and php image work and are running, so I made a controller and added a rote to it:

My routes.yaml file:

controllers:
    resource:
        path: ../src/Controller/
        namespace: App\Controller
    type: attribute

My controller:

<?php

namespace App\Controller;

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

class HomeController extends AbstractController
{
    #[Route('/', name: "home_slashed")]
    #[Route('/home', name: "home")]
    public function index(): Response
    {
        return $this->render("home/index.html.twig");
    }
}

and if I run php .\bin\console debug:router it shows:

-------------- -------- -------- ------ ------- 
  Name           Method   Scheme   Host   Path   
 -------------- -------- -------- ------ -------
  home_slashed   ANY      ANY      ANY    /
  home           ANY      ANY      ANY    /home
 -------------- -------- -------- ------ -------

BUT none of this show anything, every page that I try to load just show me a php_info page!
localhost , localhost/home or localhost/anything is the same...

I tried to change the routes, or generate any kind of error but it always show the phph_info page, even when I introduce a syntax error in the controller

what I'm missing?

5
  • Always try without Docker first, e.g. as you've managed to install PHP 8.3, test with the PHP development server first. Symfony supports it and you've one layer less that stands in the way between your own development and serving yourself. And temporarily remove Doctrine, so you can verify with as little components as necessary that your routing setup works. It all sounds a bit that you're testing for functionality pretty late in development, stash to revert back. If you made already many commits, commit, branch and reset to the root commit, then replay step by step or restart from scratch. Commented Jan 5, 2024 at 2:24
  • check your public/index.php Commented Jan 5, 2024 at 13:23
  • A friend of mine give me a sort of solution: instead of running docker with "docker compose -f "compose.yaml" up -d --build" i just had to use "docker-compose up --build" I guess @CAAHS comment points to the same, test things one by one Either way, once I run with that command, it opens correctly and routing started working Commented Jan 5, 2024 at 21:27
  • I had also checked @rickroyce answer but modifying public/index.php didn't give me any results Commented Jan 5, 2024 at 21:28
  • @Saleck: That sounds like the web server configuration, but it's hard so say from a distance with precision. The routing of it is prior to Symfony, and if the request does not get to your application but to some standard phpinfo() index.php there is little Symfony can do at that point. You could reverse engineer it: search through all text files in the whole tree for one that contains phpinfo(); and then check if any of the matching pathnames ring a bell. Then check where it is configured. Commented Jan 6, 2024 at 5:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.