Symfony2: No route found for "GET /lucky/number"
Sometimes is a cache problem. Try to remove dev folder from /project/var/cache/dev.
As authentictech says, also you can try the command:
php bin/console cache:clear
If you want to specify the environment, you should add the --env=prod property.
Try this URL:
http://[Server-IP]:8000/app_dev.php/en/lucky/number
There's a bug in the Symfony Book: they forgot the demo app support i18n.
Just add the "/en" parameter before the routing ones.
I know this question it's closed but I hope my answer can help others that are still facing this problem.
You actually don't extend Symfony Controller class. It should be class LuckyController extends Controller
// src/AppBundle/Controller/LuckyController.php
namespace AppBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Response;
class LuckyController extends Controller {
/**
* @Route("/lucky/number")
*/
public function numberAction() {
$number = rand(0, 100);
return new Response('<html><body>Lucky number: '.$number.'</body></html>');
}
}
EDIT: after all, the problem in this question was not in extending controller, so ignore my answer.
I have just added a
<?php
to the file "LuckyNumberController" and it works.... really strange.
Thanks everybody