【文件属性】:
文件名称:rewire-bundle:使用对象在Symfony34中生成路线
文件大小:12KB
文件格式:ZIP
更新时间:2024-06-06 03:23:46
PHP
使用对象生成路线
假设您有一个路由如下的博客应用程序:
/**
* @Route("/{id}", name="post_detailed")
*/
public function indexAction ( Post $ post )
{ . . . }
那么您的模板将具有以下内容:
< a xss=removed>View post a>
对于这种简单情况,将自动应用 。
问题
现在想象一下,您想将其更改为在URL中使用{slug}而不是{id} 。 更新控制器很简单,但更新所有模板却并非如此。
解决方案
该捆绑包充当ReverseParamConverter。 检查以下示例:
/**
* @Route("/{id}", name="post
【文件预览】:
rewire-bundle-master
----.gitignore(39B)
----Annotation()
--------RewireParams.php(264B)
----Resources()
--------config()
----composer.json(651B)
----README.md(4KB)
----DependencyInjection()
--------wjbRewireExtension.php(584B)
----phpunit.xml.dist(921B)
----Decorator()
--------RoutingDecorator.php(4KB)
----wjbRewireBundle.php(128B)
----Tests()
--------Fixtures()
--------Decorator()
----config.yml(107B)
----Cache()
--------RewireParamsAnnotationsWarmer.php(2KB)