symfony - Symfony - 带有 entity.propety 过滤器的下拉列表
问题描述
我有 3 个实体,分别命名为 Answer、Skill 和 Jointure。
答案和技能通过多对一关系链接到关节。
我像这样在树枝中显示它们:
class HomeController extends AbstractController
{
/**
* @var JointureRepository
*/
public function __construct(JointureRepository $repository, ObjectManager $em)
{
$this->repository = $repository;
$this->em = $em;
}
/**
* @Route("/", name="home")
*/
public function index()
{
$JointureRepository = $this->getDoctrine()->getRepository(Jointure::class);
$arrJointures = $JointureRepository->findAll();
$this->em->flush();
return $this->render('pages/home.html.twig', [
'controller_name' => 'HomeController',
'jointure' => $arrJointures,
]);
}
}
在我的树枝视图中:
{% for object in jointure %}
{% for skill in object.skills %}
{{skill.label}}
{% endfor %}
{% endfor %}
我创建了一个下拉按钮,其中列出了所有存在的 Skill.label 属性:
编辑:这是我的树枝按钮:
<div class="form-group ">
<select id="inputState " class="form-control">
<option selected>Compétence</option>
{% for object in jointure %}
{% for skill in object.skills %}
<option>{{skill.label}}</option>
{% endfor %}
{% endfor %}
</select>
</div>
</div>
<div class="col-md-2">
<button type="submit" class="btn btn-primary btn-block">Search</button>
</div>
</div>
我想在模板的视图中显示/显示所有具有此相关技能标签的 answer.userEmail 。我必须使用 EntityType 吗?非常感谢
解决方案
你应该开始使用 Symfony Forms。这是文档https://symfony.com/doc/current/forms.html。一开始并不那么简单,但绝对值得。然后你就可以使用EntityType
https://symfony.com/doc/current/reference/forms/types/entity.html
推荐阅读
- node.js - proto3 文件格式数据类型错误中的问题
- firebase - 使用 Coroutines 测试 Firebase 的使用创建用户函数并调用 await() 会导致“此作业尚未完成”
- c# - 在后台线程中从 UserControl 生成 Png
- c# - 在 Neodynamic ThermalLabel SDK [C#] 中作为流导出到 PDF 的问题
- wxmaxima - wxMaxima 从“solve”中提取解决方案
- excel - 复制并粘贴过滤列中的唯一值
- amazon-web-services - Cloudformation 自动分配运营商 IP
- pdfbox - PDFBOX - AR PL Zenkai Uni Font 的无效字符代码
- android - React Native:Google-text-to-speech (tts) 效果不佳
- python - 在 Pycharm 中运行的 python 中显示 print() 与 input() 分离