2017 © Pedro Peláez
 

library pop-nav

Pop Nav Component for Pop PHP Framework

image

popphp/pop-nav

Pop Nav Component for Pop PHP Framework

  • Monday, January 29, 2018
  • by nicksagona
  • Repository
  • 1 Watchers
  • 3 Stars
  • 1,118 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 5 % Grown

The README.md

pop-nav

Build Status Coverage Status, (*1)

Join the chat at https://discord.gg/TZjgT74U7E, (*2)

Overview

pop-nav is a component for managing and rendering an HTML navigation tree. It includes support for injecting ACL functionality to display only the certain branches of the navigation tree that the current user role is allowed to access. For that, the pop-acl component is used., (*3)

pop-nav is a component of the Pop PHP Framework., (*4)

Top, (*5)

Install

Install pop-nav using Composer., (*6)

composer require popphp/pop-nav

Or, require it in your composer.json file, (*7)

"require": {
    "popphp/pop-nav" : "^4.1.4"
}

Top, (*8)

Quickstart

First, you can define the navigation tree:, (*9)

$tree = [
    [
        'name'     => 'Users',
        'href'     => '/users',
        'children' => [
            [
                'name' => 'Roles',
                'href' => 'roles'
            ],
            [
                'name' => 'Config',
                'href' => 'config'
            ]
        ]
    ],
    [
        'name' => 'Orders',
        'href' => '/orders'
    ]
];

Then you can pass that to the nav object and render the nav:, (*10)

$nav = new Nav($tree);
echo $nav;
<nav>
    <nav>
        <a href="/users">Users</a>
        <nav>
            <nav>
                <a href="/users/roles">Roles</a>
            </nav>
            <nav>
                <a href="/users/config">Config</a>
            </nav>
        </nav>
    </nav>
    <nav>
        <a href="/orders">Orders</a>
    </nav>
</nav>

Top, (*11)

Config

You have a significant amount of control over the branch nodes and attributes via a configuration array:, (*12)

$config = [
    'top' => [
        'node'  => 'nav',
        'id'    => 'main-nav'
    ],
    'parent' => [
        'node'  => 'nav',
        'id'    => 'nav',
        'class' => 'level'
    ],
    'child' => [
        'node'  => 'nav',
        'id'    => 'menu',
        'class' => 'item'
    ],
    'on'  => 'link-on',
    'off' => 'link-off',
    'indent' => '    '
];

Using the same navigation tree from above, you can then create and render your nav object with the config:, (*13)

use Pop\Nav\Nav;

$nav = new Nav($tree, $config);
echo $nav;
    <nav id="main-nav">
    <nav id="menu-1" class="item-1">
        <a href="/users" class="link-off">Users</a>
        <nav id="nav-2" class="level-2">
            <nav id="menu-2" class="item-2">
                <a href="/users/roles" class="link-off">Roles</a>
            </nav>
            <nav id="menu-3" class="item-2">
                <a href="/users/config" class="link-off">Config</a>
            </nav>
        </nav>
    </nav>
    <nav id="menu-4" class="item-1">
        <a href="/orders" class="link-off">Orders</a>
    </nav>
</nav>

Top, (*14)

Using ACL

First, let's set up the ACL object with some roles and resources:, (*15)

use Pop\Acl\Acl;
use Pop\Acl\AclRole as Role;
use Pop\Acl\AclResource as Resource;

$acl = new Acl();

$admin  = new Role('admin');
$editor = new Role('editor');

$acl->addRoles([$admin, $editor]);

$acl->addResource(new Resource('config'));
$acl->allow('admin');
$acl->deny('editor', 'config');

And then we add the ACL rules to the navigation tree:, (*16)

$tree = [
    [
        'name'     => 'Home',
        'href'     => '/home',
        'children' => [
            [
                'name' => 'Users',
                'href' => 'users'
            ],
            [
                'name' => 'Config',
                'href' => 'config',
                'acl'  => [
                    'resource' => 'config'
                ]
            ]
        ]
    ],
    [
        'name' => 'Orders',
        'href' => '/orders'
    ]
];

We then inject the ACL object into the navigation object, set the current role and render the navigation:, (*17)

$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($editor);
echo $nav;
<nav>
    <nav>
        <a href="/home">Home</a>
        <nav>
            <nav>
                <a href="/home/users">Users</a>
            </nav>
        </nav>
    </nav>
    <nav>
        <a href="/orders">Orders</a>
    </nav>
</nav>

Because the 'editor' role is denied access to the config page, that nav branch is not rendered. However, if the role is set to $admin, the config branch renders:, (*18)

$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($admin);
echo $nav;
<nav>
    <nav>
        <a href="/home">Home</a>
        <nav>
            <nav>
                <a href="/home/users">Users</a>
            </nav>
            <nav>
                <a href="/home/config">Config</a>
            </nav>
        </nav>
    </nav>
    <nav>
        <a href="/orders">Orders</a>
    </nav>
</nav>

Top, (*19)

The Versions

29/01 2018

v2.x-dev

2.9999999.9999999.9999999-dev http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

29/01 2018

dev-master

9999999-dev http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

29/01 2018

dev-v3-dev

dev-v3-dev http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

29/01 2018

3.1.1

3.1.1.0 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

BSD-3-Clause

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

09/10 2017

3.1.0

3.1.0.0 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

03/10 2017

3.0.0

3.0.0.0 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

01/07 2016

2.1.0

2.1.0.0 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

10/05 2016

2.0.0p3

2.0.0.0-patch3 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

19/02 2016

2.0.0p2

2.0.0.0-patch2 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

18/08 2015

2.0.0p1

2.0.0.0-patch1 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php

21/07 2015

2.0.0

2.0.0.0 http://www.popphp.org/

Pop Nav Component for Pop PHP Framework

  Sources   Download

New BSD

The Requires

 

The Development Requires

acl php html navigation nav pop pop php