【问题标题】:Set default route for taxonomy为分类设置默认路由
【发布时间】:2015-08-11 11:34:35
【问题描述】:

routing.yml 中,我为类别定义了一条新路线:

categories:
    path: '/{slug}/'
    defaults:
        _controller: 'Bolt\Controllers\Frontend::taxonomy'
        taxonomytype: categories

但 Bolt 仍然按照一般模式为类别生成 url:

taxonomylink:
    path: '/{taxonomytype}/{slug}'
    defaults:
        _controller: 'Bolt\Controllers\Frontend::taxonomy'
    requirements:
        taxonomytype: 'Bolt\Controllers\Routing::getAnyTaxonomyTypeRequirement'

例如:对于类别van-gogh,生成的网址是/categories/van-gogh,但我想生成像/van-gogh 这样的网址。我希望其他分类类型保持不变:/tags/hermitage 不应变为 /hermitage,但应保持不变。

我怎样才能让 Bolt 做到这一点?谢谢你:)

【问题讨论】:

    标签: bolt-cms


    【解决方案1】:

    设置类似这样的早期路线:

    taxonomybinding:
        path: '/{taxonomytype}'
        defaults:
            _controller: 'Bolt\Controllers\Frontend::taxonomy'
        requirements:
            taxonomytype: 'Bolt\Controllers\Routing::getAnyTaxonomyTypeRequirement'
    

    【讨论】:

    • 恐怕没用。也许我没有很好地解释这个问题,我已经修改了这个问题......
    【解决方案2】:

    将分类类型设置为 category 而不是 categories

    PS 你应该定义一些要求,否则/hermitage 也会匹配,从而导致错误,因为没有包含该 slug 的类别。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 2017-02-08
      • 2015-05-16
      • 1970-01-01
      相关资源
      最近更新 更多