0

我正在使用 Symfony 3.4 和这个捆绑包https://github.com/hautelook/AliceBundle

这是我的 YAML 文件

AppBundle\Entity\Product:
  template_product (template):
    unit:              !php/const AppBundle\Entity\ItemInterface::UNIT_PCS

  product_teeth_{1} (extends template_product):
    name:              Răng sứ kim loại Mỹ ( BH 3 năm )
    price:             1500000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

  product_teeth_{2} (extends template_product):
    name:              Răng sứ Vita Đức ( BH 4 năm )
    price:             1800000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

  product_teeth_{3} (extends template_product):
    name:              Răng toàn sứ Zirconia ( CAD/CAM ) ( BH 7 năm )
    price:             3900000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

  product_teeth_{4} (extends template_product):
    name:              Răng sứ Titan ( BH 5 năm )
    price:             2400000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

  product_teeth_{5} (extends template_product):
    name:              Răng toàn sứ Full Zirconia ( CAD/CAM ) ( BH 10 năm )
    price:             4400000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

  product_teeth_{6} (extends template_product):
    name:              Răng toàn sứ Lava Plus - Ceramay (BH 20 năm)
    price:             1200000
    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

AppBundle\Entity\CategoryProduct:
  template_category_product (template):
    id:       <(substr(md5(uniqid(rand(), true)), 0, 18))>

  template_category_1 (template, extends template_category_product):
    category: "@category_product"
  template_category_2 (template, extends template_category_product):
    category: "@category_product_1"

  category_product_{1..3}_1 (extends template_category_1):
    item:     "@product_teeth_<current()>"
  category_product_{1..3}_2 (extends template_category_2):
    item:     "@product_teeth_<current()>"

AppBundle\Entity\StoreProduct:
  template_store_product (template):
    id:       <(substr(md5(uniqid(rand(), true)), 0, 18))>

  template_store_1 (template, extends template_store_product):
    store:    "@store_dentist_1"
  template_store_2 (template, extends template_store_product):
    store:    "@store_dentist_2"

  store_product_{1..3}_1 (extends template_store_1):
    item:     "@product_teeth_<current()>"
  store_product_{1..3}_2 (extends template_store_2):
    item:     "@product_teeth_<current()>"

问题是,正如您所看到的那样。他们重复多次:

    categoryProducts : ["@category_product_<current()>_1", "@category_product_<current()>_2"]
    storeItems:        ["@store_product_<current()>_1", "@store_product_<current()>_2"]

我不知道如何将 传递<current()>给模板以减少行。

任何人都可以让我知道该怎么做吗?

有什么办法可以解决我的问题吗?

我没有被卡住,但在使用夹具库时尝试在 YAML 中进行最佳实践 DRY

4

1 回答 1

0

在尝试了一些解决方案后我得到了答案。

current()应该放在最后

例如类别应该是这样的:

AppBundle\Entity\CategoryProduct:
  template_category_product (template):
    id:       <(substr(md5(uniqid(rand(), true)), 0, 18))>

  category_product_1_{1..12} (extends template_category_product):
    category: "@category_product"
    item:     "@product_teeth_<current()>"
  category_product_2_{1..6} (extends template_category_product):
    category: "@category_product_1"
    item:     "@product_teeth_<current()>"
  category_product_2_{7..12} (extends template_category_product):
    category: "@category_product_2"
    item:     "@product_teeth_<current()>"

和产品

AppBundle\Entity\Product:
  template_product (template):
    unit:              !php/const AppBundle\Entity\ItemInterface::UNIT_PCS
    categoryProducts : ["@category_product_1_<current()>", "@category_product_2_<current()>"]
    storeItems:        ["@store_product_1_<current()>", "@store_product_2_<current()>"]

  product_teeth_{1} (extends template_product):
    name:              Răng sứ kim loại Mỹ ( BH 3 năm )
    price:             1500000

  product_teeth_{2} (extends template_product):
    name:              Răng sứ Vita Đức ( BH 4 năm )
    price:             1800000
  ...
于 2021-04-14T07:06:53.733 回答