【发布时间】:2017-08-08 22:32:30
【问题描述】:
我正在制作一个公告网站,并且我正在尝试制作一个仅显示我选择的公告的研究表格。
例如,有一种表格,人们可以在其中标记角色,以便仅在具有所选角色的公告上进行搜索。
示例:
有 4 个按钮:
- 教练,
- 射手,
- 守门员,
- 边锋
我选择教练和射手。我希望只看到同时担任教练和射手角色的球员的公告(每个球员都可以担任许多不同的角色)。
在我的数组实体“poste”中,他可以扮演的所有不同角色。
示例:
mypost = $announce->getPoste();
// mypost[0] will have coach
// mypost[1] will have shooter
我尝试了很多东西,但对这种实体类型不起作用。
控制器:
$repository = $this
->getDoctrine()
->getManager()
->getRepository('PlatformBundle:Announce');
$criteria2 = $announce->getPoste();
$criteria = array_filter(array(
'game' => $game, // example: football
'region' => $announce->getRegion(), //example: Europe
'language' => $announce->getLanguage(), //example: FR
'poste' => $announce->getPoste(), //example: Goalkeeper, Shooter, Coatch
'level' => $announce->getLevel() //example: Pro
));
$announces = $repository->findBy($criteria);
<!-- It's work for everything but not for getPoste -->
$announces = $repository->findByPoste($criteria2);
<!-- no match -->
我尝试了很多东西,比如创建存储库函数和创建自定义 SQL/DQL 函数,但仍然无法正常工作。我尝试在 Google 上搜索 **Symfony 3 findBy() 数组参数”,但我没有找到任何适合我的示例的内容。
感谢您的帮助:)
【问题讨论】:
-
it never works是什么意思?具体是什么不工作?你得到什么输出?你没有输出吗?歪斜输出?错误信息? -
你好,我实际上如果我使用 $announces = $repository->findBy($criteria);一切都适用于所有变量、游戏、关卡、地区、语言,但它与 poste 不匹配,我没有找到任何公告。
-
在我的_profiler中,我可以检查参数并且没有问题,每个参数都在变量内。参数:[ 0 => 足球,1 => 欧洲,2 => FR,3 => [ 0 => 教练,1 => 射手],4 => 职业]
-
Var_dump of $criteria: C:\wamp64\www\Wolk\src\Wolk\PlatformBundle\Controller\AnnounceController.php:73: array (size=5) 'game' => string 'football' (length=8) 'region' => string 'America' (length=7) 'language' => string 'FR' (length=2) 'poste' => array (size=2) 0 => string 'coatch' (length=6) 1 => string 'shooter' (length=7) 'level' => string 'Pro' (length=3)