symfony2-如何从"dev"切换到“生产"? [英] symfony2 - how to switch from "dev" to "prod"?

查看:75
本文介绍了symfony2-如何从"dev"切换到“生产"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了symfony2,并且能够从app_dev.php开始运行它.

但是当我从app.php开始时,我得到一个错误页面404.

app.php当然在那里,并且会执行.

错误显然发生在app.php的最后一行代码之后的某个地方:

$kernel->handle(Request::createFromGlobals())->send();

我想我必须配置一个开关.

编辑:

根据GeLo的建议,我将生产版本的路由添加到app/config/routing.yml.

_welcome:
    resource: "@AcmeDemoBundle/Resources/config/routing.yml"
    prefix:     /

我创建了src/Acme/DemoBundle/Resources/config/routing.yml,内容如下:

bla:
    pattern: /
    defaults: {_controller:AcmeDemoBundle:Demo:index}

DemoController::indexAction()中放置了die(__FILE__);

一无所有;我仍然可以从app.php获取404!

编辑答案:

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

成功了.注意环境参数.

解决方案

默认情况下,Symfony 2附带有一个演示包,该演示包仅可从开发环境访问.

生产环境不包含任何路由,因此通常会出现404错误页面.

您确定在AppKernel.php中启用了捆绑软件吗?

如果是,请使用以下命令清除缓存:./app/console cache:clear

使用以下命令检查路由是否启用:./app/console router:debug

I downloaded symfony2 and I am able to run it starting from app_dev.php.

But when I start from app.php, then I get an error page 404.

app.php though is of course there and it gets executed.

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.

EDIT:

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

I created src/Acme/DemoBundle/Resources/config/routing.yml with content:

bla:
    pattern: /
    defaults: {_controller:AcmeDemoBundle:Demo:index}

In DemoController::indexAction() I placed a die(__FILE__);

nothing; I still get 404 from app.php !?

EDIT regarding the answer:

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

did the trick. mind the env-parameter.

解决方案

By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.

The production environment doesn't contain any route, so it's normal you get a 404 error page.

EDIT :

Are you sure your bundle is enable in the AppKernel.php ?

If yes, clear the cache with the following command : ./app/console cache:clear

Check if the route is enable with the following command : ./app/console router:debug

这篇关于symfony2-如何从"dev"切换到“生产"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆