H
H
hollanditkzn2018-03-14 12:00:17
Yii
hollanditkzn, 2018-03-14 12:00:17

How do I group a list in a static table?

I need to do to group all the value, but the value from the table that I displayed, it is important to add a link to the record there, but for the link I need an id, which cannot be displayed in ArrayHelper.map.
Here is my implementation
In Controller

public function actionIndex()
    {
        $users = User::find()->all();
        $users = ArrayHelper::map($users, 'nameEmployee', 'salary', 'position.name');
        return $this->render('index', compact('users'));
    }

And in the view
<?php foreach ($users as $key => $user){
                echo '<tr><td colspan="2"><strong>'.$key.'</strong></td></tr>';
                foreach ($user as $name => $salary) {
                    echo '<tr>';
                        echo '<td>'.$name.'</td>';
                        echo '<td>'.$salary.' рублей</td>';
                    echo '</tr>';
                }
            } ?>

That is, it turns out something like this
Position
Full
name Full name Full
name
Position
Full name Full
name
That is, I got them, only it is important where to get the id to attach it to the link.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-03-14
@hollanditkzn

The question is asked in such a way that nothing is clear. So let's guess. You are probably trying to group an array, but for some reason decided to use the map method, which is not intended for this. I understand you need the index method:
www.yiiframework.com/doc-2.0/guide-helper-array.ht...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question