如何在Symfony的url_for助手中使用通配符?

时间:2010-10-19 07:48:07

标签: php symfony1

在routing.yml中给出:

products:
url:   /products/*
param: { module: products, action: index }

如何使用url_for helper填充通配符部分?我的意思是:

<?= url_for('products/index?wildcard=somthingRandom') ?>

生成网址:

/products/somethingRandom

1 个答案:

答案 0 :(得分:4)

更改您的routing.yml以在匹配的网址中包含参数:

products:
url:   /products/:wildcard
param: { module: products, action: index }

然后你可以调用url_for例如:

<?php echo url_for("@products?wildcard=somethingRandom"); ?>

(使用@products表示在routing.yml中使用名为products的路由。)