【发布时间】:2014-08-02 06:08:47
【问题描述】:
如何在 Twig 中生成以下 URL?只要将 hashId 转换为 SHA1 格式,我会接受任何其他解决方案,不仅是 twig。
注意: brand.id 来自 DB,就像 1, 2, ,3, 10, 23, 69, ..... 这样的普通数字,需要进行哈希处理。我不想在数据库中存储散列数据!
像这样生成 URL:
{% for brand in brands %}
<a href="{{ path('product_delete_process', {'hashId':brand.id }) }}">Delete</a>
<br />
{% endfor %}
结果网址:
...../product/delete/process/12df54dg54th897yhjrt65DFesrSDE1123ASa
路线:
product_delete_process:
pattern: /product/delete/process/{hashId}
defaults: { _controller: ProDuctBundle:ProductDelete:process }
methods: [GET]
requirements:
hashId: "[a-zA-Z0-9]{40}"
【问题讨论】: