如何重置控制器内的symfony2缓存路由?

发布于 2024-12-26 07:07:12 字数 421 浏览 0 评论 0原文

我想动态添加路线。我正在数据库中存储文档树。根据文档在该树中的位置,我可以生成特定文档的 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 技术交流群。

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

发布评论

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

评论(1

虚拟世界 2025-01-02 07:07:12

为什么要动态生成路由?您不能使用允许斜杠的模式创建单个路由吗?

我之前使用 Symfony2 制作过类似的 CMS,并且使用了 StofDoctrineExtensionsBundle (看看 Sluggable)。

我的 Document 实体具有以下字段来支持树结构:

/**
 * @Gedmo\TreeLeft
 * @ORM\Column(name="`left`", type="integer")
 */
private $left;

/**
 * @Gedmo\TreeLevel
 * @ORM\Column(name="level", type="integer")
 */
private $level;

/**
 * @Gedmo\TreeRight
 * @ORM\Column(name="`right`", type="integer")
 */
private $right;

/**
 * @Gedmo\TreeRoot
 * @ORM\Column(name="root", type="integer", nullable=true)
 */
private $root;

/**
 * @Gedmo\TreeParent
 * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
 */
private $parent;

/**
 * @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
 * @ORM\OrderBy({"left" = "ASC"})
 */
private $children;

以及反映层次结构的 slug 字段:

/**
 * @var string $slug
 *
 * @ORM\Column(name="slug", type="string", length=255, unique=true)
 * @Gedmo\Slug(handlers={
 *      @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
 *          @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
 *          @Gedmo\SlugHandlerOption(name="separator", value="/")
 *      })
 * }, fields={"title"})
 */
private $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 and Sluggable).

My Document entity had the following fields to support tree structure:

/**
 * @Gedmo\TreeLeft
 * @ORM\Column(name="`left`", type="integer")
 */
private $left;

/**
 * @Gedmo\TreeLevel
 * @ORM\Column(name="level", type="integer")
 */
private $level;

/**
 * @Gedmo\TreeRight
 * @ORM\Column(name="`right`", type="integer")
 */
private $right;

/**
 * @Gedmo\TreeRoot
 * @ORM\Column(name="root", type="integer", nullable=true)
 */
private $root;

/**
 * @Gedmo\TreeParent
 * @ORM\ManyToOne(targetEntity="Page", inversedBy="children")
 * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL")
 */
private $parent;

/**
 * @ORM\OneToMany(targetEntity="Page", mappedBy="parent")
 * @ORM\OrderBy({"left" = "ASC"})
 */
private $children;

And a slug field which reflected the hierarchy:

/**
 * @var string $slug
 *
 * @ORM\Column(name="slug", type="string", length=255, unique=true)
 * @Gedmo\Slug(handlers={
 *      @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={
 *          @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"),
 *          @Gedmo\SlugHandlerOption(name="separator", value="/")
 *      })
 * }, fields={"title"})
 */
private $slug;

Isn't this what you're looking for?

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