Symfony - 包含entity.propriety过滤器的下拉列表

问题描述 投票:-1回答:2

我有3个名为Answer,Skill和Jointure的实体。

答案和技能与具有ManyToOne关系的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谁在我的模板中的视图中有这个相关的skill.label。我必须使用EntityType?非常感谢

symfony filter dropdown
2个回答
2
投票

您应该开始使用Symfony Forms。这是文档https://symfony.com/doc/current/forms.html。一开始并不是那么简单,但它确实令人担忧。然后你就可以使用EntityType https://symfony.com/doc/current/reference/forms/types/entity.html

© www.soinside.com 2019 - 2024. All rights reserved.