我使用的是Symfony 3.4和这个捆绑包https://github.com/hautelook/AliceBundle
这是我的YAML文件
AppBundleEntityProduct:
template_product (template):
unit: !php/const AppBundleEntityItemInterface::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"]
AppBundleEntityCategoryProduct:
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()>"
AppBundleEntityStoreProduct:
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
我在尝试了一些解决方案后得到了答案。
current()
应放在的末尾
例如,类别应该是这样的:
AppBundleEntityCategoryProduct:
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()>"
和产品
AppBundleEntityProduct:
template_product (template):
unit: !php/const AppBundleEntityItemInterface::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
...