Im completely new to Symfony so please bear with me. Im trying to configure my controller to atleast get a working webpage. I created a new Symfony project and started my server. After writing some code into MyController
<?php
namespace AppBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class MyController
{
/**
* @Route("/test")
*/
public function numberAction()
{
$prankBro= "Its just a prank bro";
return new Response($prankBro);
}
}
After trying to access localhost:8000
I get a fatal 404 error: No route found for "GET /"
Being a complete beginner I have no idea what this is. I believe it is some kind of response type, although I'm not sure. On the other hand if I use localhost:8000/test
It seems to be working fine, I get my webpage with a message saying that it was just a prank bro :) Is this how it is supposed to be in symfony? It really messes up with my brain, so if it is fine, can someone explain me why plain localhost:8000
URL gives me 404 error? Thank you!
Take note of the comment above numberAction
:
/**
* @Route("/test")
*/
That implies to me that there is a route set up for localhost:8000/test
which will execute the numberAction
method.
You need to create a method that will be your home page, and then create a route for /
which will run your new method. Then when you visit localhost:8000
, your new method will be executed.
See the Symphony documentation for details on how to set up routes.