-1

I'am using fullcalendarscheduler widget posted on github by Edofre im my yii2 project. Is there any way i could change predefined rooms displayed in the table into a data from the database.

How it looks now:

'resources'         => [
        ['id' => 'a', 'title' => 'Auditorium A'],
        ['id' => 'b', 'title' => 'Auditorium B', 'eventColor' => 'green'],
        ['id' => 'c', 'title' => 'Auditorium C', 'eventColor' => 'orange'],
        [
            'id'       => 'd', 'title' => 'Auditorium D',
            'children' => [
                ['id' => 'd1', 'title' => 'Room D1'],
                ['id' => 'd2', 'title' => 'Room D2'],
            ],
        ],
        ['id' => 'e', 'title' => 'Auditorium E'],

    ],

How i could imagine this would work:

'resources' => [
    foreach ($rooms as $key) {
        ['id' => $rooms[$key]->id, 'title' => $rooms[$key]->room],
    }
],

Edit: I have learned that i can return data using function:

$model = Workers::findAll(['user_id' => 16]);
         $table=[];
         foreach ($model as $key) {
             $work = new Resource(["id" => "a", "title" => $key->imie]);
             $table = $work;
         }

        return [
                $table,
            ];
        }

But its only displaying the last record from the table. What should i do to display entire table with $table variable?

5Feo
  • 5
  • 3
  • You should use `$table[] = $work` if you want to create list of objects. Right now every iteration of your foreach overrides previous value of `$table`. – rob006 Aug 04 '18 at 18:09
  • Ok, thanks. How can i return entire list? return [$table]; dosnt seems to work – 5Feo Aug 04 '18 at 18:55

1 Answers1

0
$model = Workers::findAll(['user_id' => 16]);
         $table=[];
         foreach ($model as $key) {
             $table[] = ["id" => "a", "title" => $key->imie];
         }

        return $table;
        //return [$table];

try these returns

Vandro.nds
  • 442
  • 3
  • 8