0

I just want to display menus from database in yii2 advanced template frontend. Also i have static menus. I am using menu widget

Here is my code

           <?php
              echo Menu::widget([
                'options' => ['class' => 'about_content'],
                'items' => CMS::getCMSPages(),
              ]);
            ?>

Here CMS::getCMSPages() will get the menus from database. And also i have static menu. So i added into the menu widget like this

           <?php
              echo Menu::widget([
                'options' => ['class' => 'about_content'],
                'items' => [[CMS::getCMSPages()],
                     ['label' => 'contact', 'url' => ['site/index']]
                 ]

              ]);
            ?>

But this is not working. Someone help me guys

Sivabalan
  • 971
  • 2
  • 18
  • 43
  • Can you provide an error output and result array of CMS::getCMSPages() method? – Valery Viktorovsky Aug 18 '15 at 11:41
  • Thank you for your reply. I didn't get any error it simply omit the dynamic menu and showing only static menu. And output of CMS::getCMSPages() is Array ( [0] => Array ( [label] => About us [url] => http://192.168.1.114:1076/ZwxQOnKQdha7SNco.html ) [1] => Array ( [label] => Terms and conditions [url] => http://192.168.1.114:1076/nabmaJDyQ02Ji09j.html ) [2] => Array ( [label] => Contact [url] => http://192.168.1.114:1076/v7tmajLaw4zqPdm6.html ) ) – Sivabalan Aug 18 '15 at 11:44

1 Answers1

1

CMS::getCMSPages() method should return properly prepared array of items. Something like this:

[
    ['label' => 'Home', 'url' => ['site/index']],
    ['label' => 'Products', 'url' => ['product/index'],
]

Also you should merge items array:

<?php
  echo Menu::widget([
    'options' => ['class' => 'about_content'],
    'items' => array_merge(CMS::getCMSPages(), [['label' => 'contact', 'url' => ['site/index']]])
  ]);
?>
Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47