【发布时间】:2014-08-11 15:53:54
【问题描述】:
我是 Symfony2 的新手,正在通过制作一个 Concert finder 应用程序来学习。
目前我有几个 yaml 路由:
london_hello_bands:
path: /hello/{band}
defaults: { _controller: LondonHelloBundle:Hello:band }
london_hello_multiple:
path: /hello/{venue}/{band}
defaults: { _controller: LondonHelloBundle:Hello:more }
这些映射到我的 HelloController 中的以下操作:
public function bandAction($band)
{
$repository = $this->getDoctrine()
->getRepository('LondonHelloBundle:Gig');
$bandinfo = $repository->findByArtist($band);
return $this->render(
'LondonHelloBundle:Hello:band.html.twig',
array('band'=>$bandinfo)
);
}
public function moreAction($venue, $band)
{
$repository = $this->getDoctrine()
->getRepository('LondonHelloBundle:Gig');
$venueinfo = $repository->findBy(
array('venueName'=>$venue, 'artist'=>$band)
);
return $this->render(
'LondonHelloBundle:Hello:venue.html.twig',
array('venues'=>$venueinfo)
);
}
这似乎一切正常,我可以使用 Doctrine 从 /hello/blur 的数据库中提取有关乐队的所有信息(例如),我可以在特定场所显示有关特定乐队的所有信息在 hello/02/blur(例如 - 02 是英国竞技场的名称)。
但是,我也希望能够在 hello/02 之类的 URL 上显示所有乐队在特定场地上演奏,但这与我的第一条路线冲突:
path: /hello/{band}
有没有一种方法可以将路线与数据库中的特定字段相关联(我在想可能类似于条件https://symfony.com/doc/current/routing.html#matching-expressions)?还是我只需要忍受这个并在 Twig 模板中添加一些逻辑来处理事情?
【问题讨论】:
标签: php symfony doctrine-orm routing yaml