Joshua Blevins Joshua Blevins - 1 month ago 22
PHP Question

Symfony controller not working

I am very new to symfony and started learning by following their instructions on the website. I created the lucky number controller, but it is not working as I had hoped.

Here is the code for the LuckyController.php file I added. I am getting a 404 error page at the url localhost/testing/web/lucky/number.

<?php

// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;

class LuckyController
{
/**
* @Route("/lucky/number")
*/
public function numberAction()
{
$number = rand(0, 100);

return new Response(
'<html><body>Lucky number: '.$number.'</body></html>'
);
}
}


I am not sure if I missed a step or if I was just suppose to create the controller. I am using Symfony 3.1 standard edition. Any help is greatly appreciated.

Answer

Well, your using the production inviroment in your request. Make sure your cache is clear or use the dev enviroment at

localhost/testing/web/app_dev.php/lucky/number.