sokyrko/yii2-menu

Yii2 module for menu creation.

Installs: 74

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 1

Open Issues: 0

Type:yii2-extension

v1.0.1 2016-11-29 15:49 UTC

This package is not auto-updated.

Last update: 2024-11-10 02:24:48 UTC


README

Yii2 module for menu creation.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist sokyrko/yii2-menu "*"

or add

"sokyrko/yii2-menu": "*"

to the require section of your composer.json file.

Run migration

./yii migrate/up --migrationPath=@vendor/sokyrko/yii2-menu/migrations

Create controllers and include menu and menu-item traits. For example:

class MenuController extends Controller
{
    use MenuTrait;
}
class MenuItemController extends Controller
{
    use MenuItemTrait;
}

Usage

Minimal configuration:

<?= MenuWidget::widget([
    'menuName' => 'main_footer',
    'menuWrapper' => '<ul class="bottom-nav">{items}</ul>',
]) ?>

Also you can define other settings:

<?= MenuWidget::widget([
    'menuName' => 'main_header',
    'template' => function (MenuItem $current) {
        return Html::tag('li', Html::a($current->title, $current->url) . '{children}', [
            'class' => ($current->url == Url::to([''])) ? 'active' : '',
        ]);
    },
    'menuWrapper' => '<nav class="nav-holder"><ul id="nav">{items}</ul></nav>',
    'subMenuWrapper' => '<div class="drop"><ul>{items}</ul></div>',
]) ?>