我現在來這里是為了一件事,它有一個名為 dayinfo 的陣列。其中我要命名專案編號,專案編號可以在變數fixed interval.date_id中找到。您知道以這種方式在禁區中傳輸資料的解決方案嗎?雖然問題可能出現在代碼的其他地方
我的樹枝代碼:
{% for fixintervall in days %}
<tr>
<th><p>
{{ fixintervall.start_day }}
</p></th>
{% for dayinfo in daysinfo %}
{% for dayinfoti in dayinfo..fixintervall.date_id %}
{% for dayin in dayinfoti %}
<p>
{{ dayin.start }} - {{ dayin.start2 }}
</p>
{% endfor %}
{% endfor %}
{% endfor %}
<br>
</tr>
<br>
{% else %}
控制器代碼:
#[Route('/cons/show/{id}', name: 'user_cons_show', methods: ['GET'])]
public function show($id, ConsRepository $consRepository): Response
{
$showcon = array();
$showconsintervall = array();
$days = array();
$dayid = array();
$daysinfo = array();
$con = $consRepository->find($id);
$showconsintervall = $con->getIntervalls();
foreach ($showconsintervall as $ex){
$datumid = $ex->getId();
$kezdodatum = $ex->getStart();
$vegdatum = $ex->getEnd();
$morepeople = $ex->getMore();
$freetime = $ex->getFreeTime();
$constime = $ex->getConsTime();
$consulid = $id;
/* Array in belüli array a cél az id?pont listázás miatt */
while($kezdodatum <= $vegdatum) {
date_default_timezone_set($kezdodatum->getTimezone()->getName());
if (date("Y-m-d",$kezdodatum->getTimestamp()) >= date('Y-m-d'))
{
array_push(
$days, [
"start_day" => date("Y-m-d",$kezdodatum->getTimestamp()),
"date_id" => $datumid,
]);
//logikai bukfenc
$start_a = date("H:i",$kezdodatum->getTimestamp());
$end_a = date("H:i",$vegdatum->getTimestamp());
$dat_a = date("H:i",$constime->getTimestamp());
$up_a = date("H:i",$freetime->getTimestamp());
if (!array_key_exists($datumid, $daysinfo)){
$start = $start_a;
$end = $end_a;
$dat = $dat_a;
$up = $up_a;
$start2 = $start;
$x = $datumid;
$x_data = array();
// echo "<br><br><br>Info:". $start2 ." - ". $end."<br>";
while ($start2 <= $end)
{
$start2_noft = (strtotime($start) (strtotime($dat)) - strtotime('00:00:00'));
$start2 = date("H:i", $start2_noft);
// echo "Eleje:".$start." ".$start2." <br>";
if ($start2 <= $end){
array_push(
$x_data,[
"start" => $start,
"start2" => $start2,
]);
}
$start_noft = strtotime($start2) strtotime($up) - strtotime('00:00:00');
$start = date("H:i", $start_noft);
// echo "Vége:".$start." ".$start2." <br>";
}
array_push(
$daysinfo,[
$x => $x_data
]);
}
}
$kezdodatum->modify(' 1 day');
}
}
array_push(
$showcon, [
"user_id" => $con->getUserId()->getId(),
"cons_id" => $id,
]);
print_r($daysinfo);
return $this->render('user/cons_show.html.twig', [
'controller_name' => 'Consulens',
'showcon' => $showcon,
'days' => $days,
'dayid' => $dayid,
'daysinfo' => $daysinfo,
]);
}
畢竟,問題是資料沒有出現。至少間隔不是

uj5u.com熱心網友回復:
該結構{% for x in y..z %}用于回圈一系列數字/字母,如檔案中所示
這將生成/編譯為類似
<?php
for($x = $y; $x < $z; $x ) {
echo $x;
}
由于您沒有提供有關陣列的太多資訊,因此dayinfoti我假設 的鍵dayinfoti將 match fixintervall.date_id。如果是這種情況,那么您可以像在PHP
{% for fixintervall in days %}
...
....
{% for data in dayinfo[fixintervall.date_id]|default([]) %}
...
...
{% endfor %}
{% endfor %}
過濾器將default解釋缺少的元素dayinfo
基本上,這消除了在回圈之前測驗fixintervall.date_id陣列中的鍵是否設定的需要dayinfo
有關動態鍵/變數的更多資訊
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/435250.html
