t4web/navigation

ZF2 Module which simplifies creationiewing menus

1.0.5 2015-12-02 14:06 UTC

This package is auto-updated.

Last update: 2024-11-26 18:53:44 UTC


README

ZF2 Module which simplifies creating and viewing menus

Usage

Add Navigation repo in yours require in composer.json:

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/t4web/navigation.git"
    }
],
"require": {
    "t4web/navigation": "dev-master"
}

In your project, for example in modules/Application/Module.php, you can add Navigation service:

'factories' => array(
      'UserNavigation' => function (ServiceLocatorInterface $sl) {
          $factory =  new T4webNavigation\Factory();
          return $factory->createService($sl);
      },
  )

In your BootstrapListener you can add menu entries:

public function onBootstrap(EventInterface $e)
{
    $sl = $e->getApplication()->getServiceLocator();
    $navigarot = $sl->get('T4webNavigation\Menu\Navigator');
    $navigator->addEntry('Dashboard', 'home', 'fa fa-dashboard');
    $navigator->addEntry('Employees', 'employees-list', 'fa fa-users');
    $navigator->addEntry(TITLE, ROUTE, ENTRY_ICON_CLASS);
}

where TITLE - title in meny entry, ROUTE - route from module config, ENTRY_ICON_CLASS - class for <i> tag.

After this you can add in your layout menu rendering:

<?= $this->navigation('UserNavigation')
    ->menu()->setUlClass('navigation')
    ->setPartial('navigation'); ?>

will be render:

<ul class="navigation">
    <li>
        <a href="/"><i class="fa fa-dashboard"></i><span class="mm-text">Dashboard</span></a>
    </li>
    <li class="active">
        <a href="/employees"><i class="fa fa-users"></i><span class="mm-text">Employees</span></a>
    </li>
</ul>

For customizing menu you can copy partial from vendor/t4web/navigation/view/partials/navigation.phtml to your module and modify it.