R
R
rinatoptimus2017-02-08 00:33:32
Yii
rinatoptimus, 2017-02-08 00:33:32

Why menu is not displayed in Yii2?

Created widget file:

use yii\bootstrap\Nav;
            echo Nav::widget(
                [
                'items' => [
                    [
                        'label' => 'Ссылка 1',
                            'url' => [
                                '#'
                            ]
                    ],
                    [
                        'label' => 'Ссылка 2',
                            'url' => [
                                '#'
                            ]
                        ]
                    ]/*,
                    [
                        'label' => 'Выпадающий список',
                        'items' => [
                            [
                                'label' => 'Ссылка 1',
                                'url' => [
                                    '#'
                                ]
                            ],
                            '<li class="divider"></li>',
                            '<li class="dropdown-header">Описание</li>',
                            [
                                'label' => 'Ссылка 2',
                                'url' => [
                                    '#'
                                ]
                            ]
                        ]
                    ]*/
                ]
            );

If you uncomment this piece inside, then an error is generated:
Setting unknown property: yii\bootstrap\Nav::0
It's not entirely clear what this is connected with?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2017-02-08
@rinatoptimus

Parentheses need to be placed correctly:

echo Nav::widget([
  'items' => [
    [
      'label' => 'Ссылка 1',
      'url' => '#'
    ],
    [
      'label' => 'Ссылка 2',
      'url' => '#'
    ],
    [
      'label' => 'Выпадающий список',
      'items' => [
        [
          'label' => 'Ссылка 1',
          'url' => '#'
        ],
        '<li class="divider"></li>',
        '<li class="dropdown-header">Описание</li>',
        [
          'label' => 'Ссылка 2',
          'url' => '#'
        ],
      ],
    ],
  ]
]);

Use a normal editor (Atom, VisualCode) or an IDE.

M
Maxim Timofeev, 2017-02-08
@webinar

This is definitely an extra nesting, you have commented out part of the code by clearly cutting off the extra ]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question