如何重置控制器内的symfony2缓存路由?
我想动态添加路线。我正在数据库中存储文档树。根据文档在该树中的位置,我可以生成特定文档的 url。问题是,每当我将文档添加到该树时,我都必须清理缓存,因为 url 匹配器已预先缓存。但是,如果我通过删除缓存目录内容来清理控制器内的缓存,则会引发错误。有什么办法,如何解决?
更多问题规范:
我需要创建更多路由,因为根据文档类型,它被称为特定控制器和操作(即使具有特定参数)。在树项实体中,我存储 url_part 和一些参数来创建特定路由(如控制器和操作),然后存储参数,将其传递给该控制器。实体具有 getRoute() 方法,该方法知道如何从其数据构建路线。然后我有例如页面文档,它是称为页面的实体,它与树项相关(我不想弄乱继承)。当我创建页面时,它知道如何填充相关树项目的数据。问题是,当我创建页面时,它不是带有现有路由的未经验证的缓存。我想要缓存路由,所以在创建页面后我想重置缓存的路由。
I want to add routes dynamically. I am storing tree of documents in database. Based on document's position in that tree i can generate url for specific document. Problem is, whenever I add document to that tree, I have to clean cache because url matcher is precached. But if I clean cache inside controller by deleting of content of cache directory error is thrown. Is there any way, how to solve it?
more problem specification:
I need more routes to create, because based on documents type, its called specific controller and action (even with specific parameters). In tree item entity i store url_part and some parameters to create particular route (like controller and action), then parameters, which are passed to that controller. Entity has method getRoute() which knows how to build route from its data. Then i have for example page document, it is entity called page and it has relation to tree item (i did not wanted to mess with inheritance). When i create page, it knows how to fill data for related tree item. Problem is, when i create page, its not unvalidated cache with existing routes. I wanna have routes cached, so after creating page i wanna reset cached routes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么要动态生成路由?您不能使用允许斜杠的模式创建单个路由吗?
我之前使用 Symfony2 制作过类似的 CMS,并且使用了 StofDoctrineExtensionsBundle (看看
树
和Sluggable
)。我的
Document
实体具有以下字段来支持树结构:以及反映层次结构的
slug
字段:这不是您要找的吗?
Why do you want to generate routes dynamically? Can't you create a single route with a pattern which allows slashes?
I've made a similar CMS using Symfony2 before, and I used StofDoctrineExtensionsBundle (have a look at
Tree
andSluggable
).My
Document
entity had the following fields to support tree structure:And a
slug
field which reflected the hierarchy:Isn't this what you're looking for?