wwaz/favigation-php
Composer 安装命令:
composer require wwaz/favigation-php
包简介
Renders recursive navigation data
README 文档
README
Favigation turns any navigation data into clean HTML markup — without wrestling with recursion, nested loops, or edge cases.
composer require wwaz/favigation-php
Requirements
- PHP
^8.1 - Composer 2
- Illuminate Support
^10|^11|^12(works great in Laravel projects, but can also be used standalone)
What it does
You give Favigation a flat list of menu items. It automatically builds a correctly nested <ul> structure — including sorting, active state, and fully customizable HTML output.
Drivers add out-of-the-box support for different data sources (e.g. WordPress) and UI frameworks (e.g. Bootstrap).
Examples
1. Render a WordPress menu in 3 lines
Got raw WordPress menu data? Just pass it in:
$menudata = [ ['ID' => 1, 'menu_item_parent' => 0, 'menu_order' => 2, 'url' => '/about', 'title' => 'About us'], ['ID' => 2, 'menu_item_parent' => 1, 'menu_order' => 3, 'url' => '/team', 'title' => 'Team'], ['ID' => 3, 'menu_item_parent' => 0, 'menu_order' => 1, 'url' => '/', 'title' => 'Home'], ]; $favigation = new wwaz\Favigation\Driver\Wordpress\Builder( $menudata, wwaz\Favigation\Driver\BasicMenuRenderer::class ); echo $favigation->toHtml();
Output:
<ul> <li><a href="/">Home</a></li> <li><a href="/about">About us</a> <ul> <li><a href="/team">Team</a></li> </ul> </li> </ul>
Sorting by menu_order, nesting via menu_item_parent — all handled automatically.
2. Bootstrap navigation with active state
Want Bootstrap-compatible markup with the current page highlighted?
$favigation = (new wwaz\Favigation\Builder( new wwaz\Favigation\Collection($data), wwaz\Favigation\Driver\Bootstrap\BootstrapMenuRenderer::class )) ->tag('ul') ->id('main-nav') ->selected('getId', 3) // Marks the item with ID 3 as active ->getBuild() ->toHtml();
The builder handles setting active classes — no need to traverse the tree yourself.
3. Fully custom HTML — icons, attributes, your own logic
Need total control over the markup?
$favigation ->setContent(function($item) { $icon = $item->getIcon() ? '<img class="icon" src="' . $item->getIcon() . '">' : ''; return $item->getUrl() ? $icon . '<a href="' . $item->getUrl() . '">' . $item->getTitle() . '</a>' : $icon . '<span>' . $item->getTitle() . '</span>'; }) ->setLiAttribute('data-id', function($item) { return $item->getId(); }) ->toHtml();
Output:
<ul> <li data-id="3"><a href="/">Home</a></li> <li data-id="1"> <img class="icon" src="about.svg"><a href="/about">About us</a> <ul> <li data-id="2"><a href="/team">Team</a></li> </ul> </li> </ul>
Every element, every attribute — fully under your control, without managing the tree yourself.
Why Favigation?
| Without Favigation | With Favigation |
|---|---|
| Write recursive functions yourself | toHtml() |
| Implement sorting manually | Automatic via menu_order |
| Set active classes by hand | ->selected('getId', $currentId) |
| Hard-wire framework-specific markup | Swap out a driver |
Custom Drivers
Favigation is extensible — write your own driver to support any data structure. Documentation available in the repository.
Developer Experience
Useful local commands:
composer test
composer analyse
composer validate
Driver\Wordpress\Builder is provided as a backward-compatible alias and internally reuses WordpressBuilder.
License
MIT License — see LICENSE for details.
wwaz/favigation-php 适用场景与选型建议
wwaz/favigation-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 42 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「wordpress」 「navigation」 「headless」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 wwaz/favigation-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 wwaz/favigation-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 wwaz/favigation-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block to display a list of links to child pages, or pages in current level
Laravel Menu management
Alfabank REST API integration
Create simple top navigation for laravel
GUI for monitoring usage in real-time for appui
Yii 2 Navigation Routing Locator for active menu identification
统计信息
- 总下载量: 42
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-12