D
D
Dmitry2020-10-05 10:03:04
Yii
Dmitry, 2020-10-05 10:03:04

How to remove name repetitions?

There is a list of ingredients, at the top of the fields there is the name of the dish to which the ingredient belongs, please tell me how to make sure that the name of the dish does not repeat, but is displayed only once!?

There is this:
5f7ac4bfced0b005504063.jpeg

And to do this:
5f7ac51030fd1687277273.jpeg

My code in the view:

<?php foreach ($values as $index => $value): ?>
    	<div class="disabled"><?=$value->valuesAttribute->name?></div>
        <?=$form->field($value, "[$index]name")->label(false);?>
    <?php endforeach; ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Dobryshin, 2020-10-05
@JoneCode

$label='';
foreach ($values as $index => $value):
     if ($label != $value->valuesAttribute->name) {
           $label = $value->valuesAttribute->name;
          ?>
          <div class="disabled"><?=$value->valuesAttribute->name?></div>
          <?php
     }
     ....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question