popphp/pop-nav
Composer 安装命令:
composer require popphp/pop-nav
包简介
Pop Nav Component for Pop PHP Framework
README 文档
README
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.
pop-nav is a component of the Pop PHP Framework.
Install
Install pop-nav using Composer.
composer require popphp/pop-nav
Or, require it in your composer.json file
"require": {
"popphp/pop-nav" : "^4.1.5"
}
Quickstart
First, you can define the navigation tree:
$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:
$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>
Config
You have a significant amount of control over the branch nodes and attributes via a configuration array:
$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:
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>
Using ACL
First, let's set up the ACL object with some roles and resources:
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:
$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:
$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:
$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>
popphp/pop-nav 适用场景与选型建议
popphp/pop-nav 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.31k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2014 年 12 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「html」 「navigation」 「acl」 「nav」 「pop」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 popphp/pop-nav 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 popphp/pop-nav 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 popphp/pop-nav 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Texy converts plain text in easy to read Texy syntax into structurally valid (X)HTML. It supports adding of images, links, nested lists, tables and has full support for CSS. Texy supports hyphenation of long words (which reflects language rules), clickable emails and URL (emails are obfuscated again
A block to display a list of links to child pages, or pages in current level
HTML and form generation
A modern HTML DOM parser for PHP using DOMDocument and Symfony CssSelector.
Reusable utilities library for Lacus Solutions' packages (type description, HTML escaping, random sequences)
Laravel Menu management
统计信息
- 总下载量: 7.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 12
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-12-08