【问题标题】:How to store the url in the database correctly?如何正确地将url存储在数据库中?
【发布时间】:2021-09-30 19:41:11
【问题描述】:

我和其他人一样在数据库中有一个菜单:

id parent_id url
1 0 clothes
2 1 men
3 2 pants
3 1 women
4 3 pants

我来web.com/clothes/men/pants,我在控制器里抓到了url:

总是收集所有的 URL 很不方便:

  • 对于菜单
  • 了解我们属于哪个类别以便正确展示产品

也许我应该立即将完整的网址存储在数据库中?

共有1800个类别!并缓存所有内容!

id parent_id url
1 0 clothes
2 1 clothes/men
3 2 clothes/men/pants
3 1 clothes/women
4 3 clothes/women/pants

【问题讨论】:

    标签: php laravel routes


    【解决方案1】:

    菜单由不同层次的层级元素组成。因此,一种合乎逻辑的方法是将它们存储在不同的表中,具体取决于那里的级别,所以:

    1 级:

    衣服

    2 级:

    男士

    女性

    3 级:

    裤子

    这种混合方法使分类级别的构建变得容易,而无需存储数以千计难以维护的完整 url 路径。

    【讨论】:

      猜你喜欢
      • 2018-08-11
      • 2017-12-24
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 1970-01-01
      • 2016-10-20
      相关资源
      最近更新 更多