我已经在C:\ xampp \ htdocs \ sym1 \ blog中安装了Symfony2 2.7,我手动创建了一个新的控制器Document
<?php
// 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>'
);
}
}
但是当我去
http://localhost/sym1/blog/web/lucky/number
或
http://localhost/sym1/blog/app_dev.php/lucky/number
它只显示
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.
任何人都知道问题是什么?
- 更新 -
我刚刚发现此评论
#RewriteRule .? %{ENV:BASE}/app.php [L]
然后添加这两行
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app_dev.php [QSA,L]
没问题,但页面底部附有一个性能栏。
答案 0 :(得分:7)
我认为,您不了解Symfony2中的环境概念。在第一种情况下,Apache从web文件夹执行了app.php。它是您应用的生产版本。许多缓存文件在每个请求上都没有刷新。这就是您没有看到更改的原因。您必须先通过console命令清除缓存。
php app/console cache:clear --env=prod
在第二种情况下,Apache执行app_dev.php。这是发展环境。您可以立即看到您的更改,还可以看到对开发非常有用的developmnet工具栏。工具栏仅存在于开发环境中。
http://symfony.com/doc/current/book/configuration.html#environments
答案 1 :(得分:1)
另一种可能的解决方案:
php bin/console cache:clear --env=prod