承接 pavelkucera/navigation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pavelkucera/navigation

最新稳定版本:v1.0.0

Composer 安装命令:

composer require pavelkucera/navigation

包简介

README 文档

README

A simple tool helping you to create a structured navigation really fast.

License

BSD 3-Clause

Dependencies

Installation

Through composer:

$ composer install pavelkucera/navigation

Usage

I wanna a navigation now!

It is a way too easy to create a structured navigation.

use PK\Navigation\Node;

$navigation = new Node();
$navigation->addChild(new Node('Homepage', 'Homepage:'));
$navigation->addChild(new Node('Blog:', 'Blog:'));
$portfolio = $navigation->addChild(new Node('Portfolio'));
	$portfolio->addChild(new Node('Nette', 'Portfolio:nette'));
	$portfolio->addChild(new Node('JavaScript', 'Portfolio:javascript'));
	$portfolio->addChild(new Node('Android', 'Portfolio:android'));

There is no limitation to the number of children.

I need to render it

Since every site has its own way of rendering its navigation, this tool does not come with any “official” Nette\Application\UI\Control implementation. Nevertheless you can find an example in the examples directory.

The tool provides a view object you can easily read.

use PK\Navigation\Node;
use PK\Navigation\NodeView;

$navigation = new Node('navigation');
$navigation->addChild(new Node('Homepage', 'Homepage:'));
$navigation->addChild(new Node('Blog:', 'Blog:'));

$view = $navigation->render(new NodeView());
$view->label; // 'navigation'
$view->link; // NULL
$view->active; // FALSE
$view->children; // array(2)

I need to set the order

Pass the child priority as the second parameter (higher is better). In case of the same priority, time is critical (sooner is better).

use PK\Navigation\Node;

$navigation = new Node();
$navigation->addChild(new Node('Homepage', 'Homepage:'), 1);
$navigation->addChild(new Node('Blog:', 'Blog:'), 5);

I need to mark active node(s)

There's a method for it!

use PK\Navigation\Node;

$navigation = new Node();
$navigation->addChild(new Node('Homepage', 'Homepage:'), 1);
$navigation->addChild(new Node('Blog:', 'Blog:'), 5);

$navigation->resolveActive(function($link) {
	return $presenter->isLinkCurrent($link);
});

It is always called upon the whole node tree.

When a node is active, I need its parent to be active too

Pass TRUE as the second parameter.

$navigation->resolveActive($callback, TRUE);

I need to get an array of active nodes

use PK\Navigation\NodeView;

$navigation->renderActiveNodes(new NodeView());

Method renders the node upon which the method is called to the given view object and all the active children including nested ones into the property $children.

Not everyone can see all the navigation items

You can either restrict access based on the user role or on the user permissions. Be aware, you can not combine both ways.

use PK\Navigation\Node;
use PK\Navigation\NodeView;

$roleRestricted = new Node('the Jedi Temple', 'Entrance:');
$roleRestriected->restrictAccess('jedi'); // only jedi can access the jedi temple
$roleRestriected->render(new NodeView(), function($role) {
	return $role === 'jedi';
});

$permissionsRestricted = new Node('Abydos', 'Stargate:abydos');
$permissionsRestricted->restrictPermissions('startgate', 'access'); // only people with access to a stargate can travel to Abydos
$permissionsRestricted->render(new NodeView(), function($resource, $privilege) {
	return $resource === 'stargate' && $privilege === 'access';
});

Passing the callback to the render method is critical, it determines whether a node is rendered or not. If the callback returns TRUE the node is rendered, otherwise it is not.

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-01-11