Answer the question
In order to leave comments, you need to log in
Yii2 php foreach and how to favorably set if conditions?
I understand that it is not clear from the question what I want, I could not formulate.
And so, there is sorting in the controller.
public function actionIndex()
{
$server_list_earli = Listserver::find()->orderBy(['status'=> SORT_ASC, 'date' => SORT_ASC])->all();
return $this->render
('index',['list_earlier' => $server_list_earli]);
}
<div class="box__list box__solar">
<?php $showed = false; ?>
<?php foreach($list_earlier as $list):?>
<?php
if ( $list->date_start < date("Y-m-d") && $list->date_end > date("Y-m-d") ) {
$status = $list->status;
}else {
$status = 'simple__content__section'';
}
if ( $status == 'content__section' ) {
$icon_star = $a;
$priority = 1;
$icon_round = $list->icon_item;
}else if ( $status == 'midle__content__section' ) {
$icon_star = $b;
$priority = 2;
$icon_round = $list->icon_item;
}else if ( $status == 'under__content__section' ) {
$icon_star = $c;
$priority = 3;
$icon_round = $list->icon_item;
}else if ( $status == 'simpler__content__section'' ) {
$icon_star = ' ';
$priority = 5;
$icon_round = ' ';
}
?>
<?php if ($list->date >= date('Y-m-d')): ?>
<?php if ($priority < 3): ?>
<?php if(!$showed){echo '<div class="box__headline heading__hight"><h3>Заголовок<span class="title__line"></span>Сервера <i class="fa fa-usd" aria-hidden="true"></i></h3></div>';$showed = true;} ?>
<div class="box__span <?= $status ?>">
<span class="b__link__item item__icon"><?= $icon_star ?></span>
<span class="b__link__item item__name"><?= $list->name ?></span>
<span class="b__link__item item__bonus"><?= $icon_round?></span>
<span class="b__link__item item__date"><?= Yii::$app->formatter->asDate($list->date) ?></span>
</div>
<?php endif; ?>
<?php endif; ?>
<?php endforeach;?>
</div>
</div>
<?php if ($list->date >= date('Y-m-d')): ?>
<?php if ($priority < 3): ?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question