PHP code example of pavelkucera / navigation

1. Go to this page and download the library: Download pavelkucera/navigation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pavelkucera / navigation example snippets


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'));

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)

use PK\Navigation\Node;

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

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);
});

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

use PK\Navigation\NodeView;

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

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';
});
TRUE
TRUE