t4web / navigation
简化创建和查看菜单的ZF2模块
1.0.5
2015-12-02 14:06 UTC
Requires
- php: >=5.4.0
- zendframework/zend-modulemanager: ~2.5.0
- zendframework/zend-navigation: ~2.5.0
- zendframework/zend-servicemanager: ~2.5.0
Requires (Dev)
README
简化创建和查看菜单的ZF2模块
用法
在composer.json中添加Navigation仓库的要求
"repositories": [ { "type": "git", "url": "https://github.com/t4web/navigation.git" } ], "require": { "t4web/navigation": "dev-master" }
在您的项目中,例如在modules/Application/Module.php中,您可以添加Navigation服务
'factories' => array( 'UserNavigation' => function (ServiceLocatorInterface $sl) { $factory = new T4webNavigation\Factory(); return $factory->createService($sl); }, )
在您的BootstrapListener中,您可以添加菜单项
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); }
其中 TITLE
- 菜单项的标题,ROUTE
- 模块配置中的路由,ENTRY_ICON_CLASS
- <i> 标签的类。
之后,您可以在您的布局中添加菜单渲染
<?= $this->navigation('UserNavigation') ->menu()->setUlClass('navigation') ->setPartial('navigation'); ?>
将会渲染
<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>
为了自定义菜单,您可以将vendor/t4web/navigation/view/partials/navigation.phtml中的部分复制到您的模块中并进行修改。