hkguile hkguile - 10 months ago 82
PHP Question

symfony2 create first controller but 404

I've installed Symfony2 2.7 in C:\xampp\htdocs\sym1\blog, I created a new controller manually following this Document

// 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>'

but when i go to




it just displays

Oops! An Error Occurred

The server returned a "404 Not Found".

Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

anyone knows what's the problem?


i'm just found comment this

#RewriteRule .? %{ENV:BASE}/app.php [L]

and then add these two lines

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]

will ok, but there is a performance bar attached at the bottom of the page.

kba kba
Answer Source

I think, you don't understand the concept of environments in Symfony2. In the first case Apache executed app.php from web folder. It is production version of your app. A lot of cached files that are not refreshed on each request. This is the reason why you don't see your changes. You have to clear a cache first by console command.

php app/console cache:clear --env=prod

In second case, Apache executes app_dev.php. This is development enviroment. You see your changes immediately and also can see the developmnet toolbar which is very useful for development. Toolbar is present only in development enviroment.