John Davidson

php - Variable transfer for loop to loop, or data error

0 comments
Message:


I’m here for one thing right now that has an array called dayinfo. In which I want to name the item number, the item number can be found in the variable fixed interval.date_id. Do you know a solution for transferring data in the forban in this way?
Although the problem may arise elsewhere in the code


My twig code:


   {% 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 %}

Controller Code:


 #[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,
]);
}

And the problem is, after all, that the data does not appear. At least the intervals are not




My Answer:
{% set dayinfo = [] %}
{% for fixintervall in days %}
{% set dayinfo = dayinfo|merge({(fixintervall.date_id): fixintervall}) %}
{% endfor %}

Rate this post

3 of 5 based on 9664 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us