1. Go to this page and download the library: Download popphp/pop-nav 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/ */
// Append a new top-level branch (pass true as the 2nd argument to prepend it instead)
$nav->addBranch([
'name' => 'Orders',
'href' => '/orders'
]);
// Insert a leaf into an existing branch, found by matching 'name'
$nav->addLeaf('Users', [
'name' => 'Permissions',
'href' => 'permissions'
]);
// Only match a 'Users' branch at the top level (depth 0)
$nav->addLeaf('Users', ['name' => 'Permissions', 'href' => 'permissions'], 0);
use Pop\Nav\Nav;
$nav = new Nav($tree, $config);
echo $nav;
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');
$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($editor);
echo $nav;
$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($admin);
echo $nav;
$acl->addResource(new Resource('reports'));
// No allow() or deny() call for 'reports' at all.
$tree[0]['children'][] = [
'name' => 'Reports',
'href' => 'reports',
'acl' => ['resource' => 'reports']
];
$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($editor);
echo $nav; // 'Reports' renders - nothing denied it, so it's allowed by default
$nav = new Nav($tree);
$nav->setAcl($acl);
$nav->setRole($editor);
$nav->setAclStrict(true);
echo $nav; // 'Reports' is now hidden - nothing explicitly allowed it
$nav->setAcl($acl);
$nav->addRoles([$editor, $admin]); // 'config' is still hidden - editor's deny wins
echo $nav;
use Pop\Acl\AclRole as Role;
use Pop\Acl\Policy\PolicyTrait;
class OwnerPolicy extends Role
{
use PolicyTrait;
// Method name must match the node's 'acl.permission'
public function edit($role, $resource = null): bool
{
return $this->isOwnerOfCurrentPage(); // your own app-specific logic
}
}