Symfony2 缓存和路由生成

发布于 2024-12-19 08:14:30 字数 1436 浏览 3 评论 0原文

这是我第一次尝试使用 Symfony2 创建一些东西。
我有我的数据库,我想从它自动生成模型。所以我运行

php app/console doctrine:mapping:import MYBundle php

php app/console doctrine:generate:entities MYBundle

确定,我的实体现在已创建。
然后我想创建基本的增删改查操作,所以我运行

php app/console generate:doctrine:crud

Which is Should 为所选模型创建控制器、视图和路由表。
问题是路由表没有生成,所以如果我导航到 /posts,并且我的 index.html.twig 包含

path('users_show', { 'id': entity.id }) }}

我的服务器发送 500 错误。
Symfony 甚至没有捕获该错误并向我显示漂亮的格式化异常。

此外,如果我修改我的index.html.twig,它将保持缓存状态,直到我不 rm -R /app/cache/dev 文件夹。
有没有办法禁用缓存?

[编辑]

我的routing_dev.yml

_welcome:
    pattern:  /
    defaults: { _controller: OREBundle:Default:index }

_assetic:
    resource: .
    type:     assetic

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_main:
    resource: routing.yml

和我的routing.yml

_welcome:
    pattern:  /
    defaults: { _controller: OREBundle:Default:index }
_users:
    pattern: /users
    defaults: { _controller: OREBundle:Users:index}

this is my first attempt to create something with Symfony2.
I have my database, and I wanted to generate models from it automatically. So I run

php app/console doctrine:mapping:import MYBundle php

and

php app/console doctrine:generate:entities MYBundle

Ok, my entities are now created.
Then I wanted to create basic crud operations, so i run

php app/console generate:doctrine:crud

Which is supposed to create Controllers,Views and Routing table for the selected models.
The problem is that the routing table isn't generated, so if i navigate to, let's say, /posts, and my index.html.twig contains

path('users_show', { 'id': entity.id }) }}

My server send a 500 Error.
Symfony doesn't even catch that error and show me the nice formatted exception.

Furthermore if i modify my index.html.twig, it will remain cached until i don't rm -R the /app/cache/dev folder.
Is there a way to disable caching?

[EDIT]

my routing_dev.yml

_welcome:
    pattern:  /
    defaults: { _controller: OREBundle:Default:index }

_assetic:
    resource: .
    type:     assetic

_wdt:
    resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
    prefix:   /_wdt

_profiler:
    resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
    prefix:   /_profiler

_configurator:
    resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
    prefix:   /_configurator

_main:
    resource: routing.yml

and my routing.yml

_welcome:
    pattern:  /
    defaults: { _controller: OREBundle:Default:index }
_users:
    pattern: /users
    defaults: { _controller: OREBundle:Users:index}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰葑 2024-12-26 08:14:30

我猜您从未使用 --with-write 选项运行命令。来自 symfony2 文档:

--with-write: (no) [值: yes|no] 是否生成新建、创建、编辑、更新和删除操作

您可以尝试使用此命令再次运行 generate-entities选项。

I'm guessing that you never ran your command with the --with-write option. From the symfony2 docs:

--with-write: (no) [values: yes|no] Whether or not to generate the new, create, edit, update and delete actions

You can try running your generate-entities again with this option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文