How to have twig path() with silex slug?

本秂侑毒 提交于 2019-12-14 04:04:33

问题


In silex I have something like

$controllers->get('/{id}', 'Controllers\\Login::index')->bind('login');

when in twig I try to get path('login') I get exception

("Some mandatory parameters are missing ("id") to generate a URL for route "login"."). ?

I know this is because of {id} and I have to pass a second parameter to path() but how should it look like?


回答1:


In order to pass parameters to twig path, use the following syntax:

{{ path('login', {'id': 'your-id-here'}) }}

you can have a look at the documentation here:

Path() function documentation, symfony

You can pass several parameters as explained here:

SO: several paremeters in twig



来源:https://stackoverflow.com/questions/47190538/how-to-have-twig-path-with-silex-slug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!