How to transfer array values from a database to a variable? I want to make a managed menu for the administrator. On the frontend in layouts / main menu is written here
$menuItems = [ ['label' => $item1, 'url' => [$item2]], ]; I make a query to the database to get the data $query = Menu::find()->all(); I'm trying to pull
foreach ($query as $index => $array) { $menuItems = [ ['label' => $item1, 'url' => [$item2]], ]; } But it displays only the last value in the database. Tried to pass a value on an array, like so, an error
$item1 = []; $item2 = []; $query = Menu::find()->all(); foreach ($query as $index => $array) { $item1[$index]['label'] = $array['text']; $item2[$index]['url'] = $array['url']; } $menuItems = [ ['label' => $item1, 'url' => [$item2]], ]; And how to write ?? In the debugger you can see that the parameters are passed
in C: \ OpenServer \ domains \ localhost \ path \ frontend \ views \ layouts \ main.php at line 72 - yii \ base \ Widget :: widget (['options' => [' class' => 'navbar-nav navbar-right '],' items '=> [[' label '=> [[' label '=>' Album '], [' label '=>' About university '], [' label '=>' Contacts ']],' url '=> [[[' url '=>' category / '], [' url '=>' / about '], [' url '=>' / contact ']]]], '
But mistake
htmlspecialchars () expects parameter 1 to be string, array given