【问题标题】:Bolt CMS - automatic relationsBolt CMS - 自动关系
【发布时间】:2015-09-28 12:08:09
【问题描述】:

我是 Bolt CMS 的新手,但目前看起来还不错。我现在的目标是为文章创建评分。为此,我创建了ratings 内容类型,并在那里放置了article_iduser_idrating 字段。现在我如何设置这些字段来创建它们之间的关系?

由于 Bolt 支持 Symfony,我希望它使用 Doctrine 及其工具。

我目前ratings 的内容类型很差:

ratings:
    name: Ratings
    slug: ratings
    singular_name: Rating
    singular_slug: rating
    fields:
        article_id:
            type: integer
        user_id:
            type: integer
        rating:
            type: integer

【问题讨论】:

    标签: symfony bolt-cms


    【解决方案1】:

    评级究竟应该做什么?访问者必须能够评价文章吗?在这种情况下,您可能会查看 rateit 扩展 http://extensions.bolt.cm/view/5d137130-4ab8-4e75-9d58-43f3f99c5a5a

    【讨论】:

    • 它实际上有点复杂 - 我计划有一些类似“最佳文章”和最高评价的文章等。我更愿意这样做 我的方式 依赖插件。
    • 您可以在螺栓内容类型中使用关系,请参阅docs.bolt.cm/relationships .. 所以您可能有一个内容类型文章和一个内容类型评级,其中评级与文章相关但界面会变得非常令人费解的
    • 我同时拥有 articlerating 内容类型,但我不知道如何以我想要的方式加入它们。我需要自动绑定,而不是手动从 CMS 面板中挑选的东西。
    • 您可以在您的内容类型中添加一个名为rating 并带有1-5 星的选择字段,然后使用{% setcontent topten = 'article' limit 10 orderby '-rating' %} 获得评分最高的十篇文章docs.bolt.cm/content-fetching
    【解决方案2】:

    如果我理解了你的问题,你想要的是拥有、评分和文章的关系。 这是代码。文章有很多评分。

    ratings:
        name: Ratings
        singular_name: Rating
        fields:
            name:
                label: Name
                type: text
                group: General
            email:
                label: Email
                type: text
                group: General
    
    articles:
        name: Articles
        singular_name: Article
        fields:
            name:
                label: Name
                type: text
                group: General
        relations:
            ratings:
                multiple: true
                label: "Choose ratings"
    

    了解 BOLT CMS 是在 Symphony 和 Silex 的肩膀上构建的,这一点很重要。但是为了获取内容,您不必使用 Doctrine Query。如果您使用的是 BOLT 3.* 或 Backend.php,如果您使用的是旧版本,我建议您查看包含 Records.php 的 Backend 文件夹。检查 editContent 操作。如果你想在 Frontend.php 上,很容易按照代码进行操作。

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-29
      • 2016-09-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多