简体   繁体   English

Symfony2演示扩展未启用

[英]Symfony2 demo extension is not enabled

I'm starting on learning symfony2, and downloaded the symfony with vendors. 我开始学习symfony2,并向供应商下载了symfony。 But I'm not getting run symfony on the production environment, he returns the following error: 但是我没有在生产环境上运行symfony,他返回以下错误:

request.CRITICAL: Twig_Error_Runtime: The "demo" extension is not enabled in "AcmeDemoBundle: Demo: hello.html.twig" at line 9 request.CRITICAL:Twig_Error_Runtime:在第9行的“ AcmeDemoBundle:Demo:hello.html.twig”中未启用“ demo”扩展名

I've tried setting the config.yml like this: 我试过像这样设置config.yml:

services:
     twig.extension.acme.demo:
         class: Acme\DemoBundle\Twig\Extension\DemoExtension
         tags:
             - {Name: twig.extension}
         arguments:
             - @ Twig.loader

I've tried to add also the bundle Acme in autoload.php, but still did not work ... still gives the same error. 我尝试过在autoload.php中添加捆绑包Acme,但仍然无法正常工作……仍然给出相同的错误。

The only way to make it work is to set debug to true on this line: 使其起作用的唯一方法是在此行上将debug设置为true:

$kernel = new AppKernel ('prod', false);

but I do not want to do this in a production environment because it would not be good. 但我不想在生产环境中执行此操作,因为那样不好。

Could anyone help me please? 有人可以帮我吗?

Ps.: Sorry for my english 附注:对不起,我的英语

Edit: 编辑:

In the view has a code like this: {% set code = code(_self) %} 在视图中有这样的代码:{%set code = code(_self)%}

If i change the part code(_self) to something else, it work perfectly... 如果我将零件代码(_self)更改为其他内容,则可以正常使用...

But, why not run with that code? 但是,为什么不运行该代码呢?

You're probably having this issue because you're accessing the prod version where the AcmeDemoBundle is only loaded in the development environment. 您可能会遇到此问题,因为您正在访问仅在开发环境中加载AcmeDemoBundle的产品版本。

Make sure that you're accessing app_dev.php (development environment) instead of using the .htaccess or app.php (production environment) methods. 确保您正在访问app_dev.php (开发环境),而不是使用.htaccessapp.php (生产环境)方法。

Note: I'm assuming that the code that you're playing with is not production code. 注意:我假设您正在使用的代码不是生产代码。 If it is, you should create the twig extension in your own bundle that is loaded in all environments. 如果是,则应在所有环境中都已加载的自己的捆绑软件中创建twig扩展。

Be careful with the syntax : 请注意语法:

services:
  twig.extension.acme.demo:
    class: Acme\DemoBundle\Twig\Extension\DemoExtension
    arguments:
         - @twig.loader
    tags:
         - { name: twig.extension }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM