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

2

1 Answer 1

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']]])
  ]);
?>
Sign up to request clarification or add additional context in comments.

2 Comments

But when i put only CMS::getCMSPages() it actually displays the menu items. So it means its in the correct format only. Did i thinking right?
Thank you Valery Viktorovsky. Superrrrrrrrrrrrrrrrrrrrrr

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.