symfony2 - 如何从“开发"切换“生产"? [英] symfony2 - how to switch from "dev" to "prod"?
问题描述
我下载了 symfony2,我可以从 app_dev.php 开始运行它.
I downloaded symfony2 and I am able to run it starting from app_dev.php.
但是当我从 app.php 启动时,我得到一个错误页面 404.
But when I start from app.php, then I get an error page 404.
app.php 当然存在并且它会被执行.
app.php though is of course there and it gets executed.
该错误显然发生在 app.php 中最后一行代码之后的某处:
The error happens apparently somewhere after the last line of code in app.php:
$kernel->handle(Request::createFromGlobals())->send();
我想我必须在某处配置一个开关.
I guess there is a switch somewhere I have to configure.
编辑:
按照 GeLo 的建议,我将生产版本的路由添加到 app/config/routing.yml.
As suggested by GeLo I added the routing for the production version to app/config/routing.yml.
_welcome:
resource: "@AcmeDemoBundle/Resources/config/routing.yml"
prefix: /
我用内容创建了 src/Acme/DemoBundle/Resources/config/routing.yml:
I created src/Acme/DemoBundle/Resources/config/routing.yml with content:
bla:
pattern: /
defaults: {_controller:AcmeDemoBundle:Demo:index}
在 DemoController::indexAction()
中,我放置了一个 die(__FILE__)
;
In DemoController::indexAction()
I placed a die(__FILE__)
;
什么都没有;我仍然从 app.php 得到 404 !?
nothing; I still get 404 from app.php !?
关于答案的
./app/console --env=prod cache:clear
成功了.注意 env 参数.
did the trick. mind the env-parameter.
推荐答案
默认情况下,Symfony 2 提供了一个演示包,它只能从开发环境中访问.
By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.
生产环境不包含任何路由,所以出现404错误页面是正常的.
The production environment doesn't contain any route, so it's normal you get a 404 error page.
您确定您的包在 AppKernel.php 中启用了吗?
Are you sure your bundle is enable in the AppKernel.php ?
如果是,请使用以下命令清除缓存:./app/console cache:clear
If yes, clear the cache with the following command : ./app/console cache:clear
使用以下命令检查路由是否启用:./app/console router:debug
Check if the route is enable with the following command : ./app/console router:debug
这篇关于symfony2 - 如何从“开发"切换“生产"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!