別の配列に存在する要素で配列をフィルタリングする必要があります。
詳細には、コントローラーに2つの変数(配列)があります。1つはすべてのユーザーを含み、もう1つは評価に参加しているユーザーです。必要なのは、3番目の変数/またはすべての残りを含む小枝(配列)のリストです-したがって、すべての評価のドロップダウンリストからそれらから選択できます(すでに評価されている名前は表示されませんドロップダウンリスト)。
私は今、これを行うための最良のアプローチは何であるか疑問に思っています。これを小枝またはコントローラーで行う必要がありますか?
ありがとうございました!
小枝:
<select name="user" >
{% for user in users %}
<option value="{{ user.idUser }}" label="{{ user.name }} ">
{% endfor %}
</select>
コントローラ:
$evals = $this
->getDoctrine()
->getRepository(User::class)
->findUserGroups(); // this is my own function (based on SQL query) from repository that searches for those who participated in evaluation
$users = $this
->getDoctrine()
->getRepository(User::class)
->findAll(); //this is a variable that contains ALL users (including those who already participated in evaluation)
これはコントローラーで処理するのが最適であり、phpを使用して処理できますarray_diff
。
コントローラ:
$evals = $this
->getDoctrine()
->getRepository(User::class)
->findUserGroups();
$users = $this
->getDoctrine()
->getRepository(User::class)
->findAll();
$non_evals = array_diff($users, $evals);
その後、小枝で:
<select name="user" >
{% for user in non_evals %}
<option value="{{ user.idUser }}" label="{{ user.name }} ">
{% endfor %}
</select>
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加