atk14/menu14
Composer 安装命令:
composer require atk14/menu14
包简介
Menu14 is a menu generator designated for ATK14 applications
README 文档
README
Menu14 is a menu generator designated for ATK14 applications.
Menu14 has simple configuration that keeps in mind the ATK14 concept of controllers and actions.
Menu14 can build branched navigation structures. There is no limit of submenu levels count.
Menu14 can also be used for breadcrumbs.
Menu14 implements ArrayAccess, Iterator and Countable for easy usage.
Basic usage
In a controller:
$menu = new Menu14();
$submenu = $menu->add("Archive");
$submenu->add("Whole archive",["articles/index"]);
$top_articles = $submenu->add("Top articles","top_articles");
$top_articles->add("Last Month","top_articles/last_month");
$top_articles->add("Last Year","top_articles/last_year");
// another submenu
$submenu = $menu->add("Information");
$submenu->add("About us","main/about");
$submenu->add("Contact","main/contact");
// disabled items should be displayed non clickable
$user_menu = $menu->add("User");
$user_menu->add("Login","logins/create_new",["disabled" => $is_user_logged]);
$user_menu->add("Logout","logins/destroy",["disabled" => !$is_user_logged]);
$user_menu->add("Profile","users/detail",["disabled" => !$is_user_logged]);
$this->tpl_data["menu"] = $menu;
In a template:
{* file: shared/_menu.tpl *}
{if !$menu->isEmpty()}
<ul>
{foreach $menu->getItems() as $item}
<li{if $item->isActive()} class="active"{/if}{if $item->isDisabled()} class="disabled"{/if}>
{if $item->getUrl() && !$item->isDisabled()}
<a href="{$item->getUrl()}">{$item->getTitle()}</a>
{else}
{$item->getTitle()}
{/if}
{* recursion *}
{render partial="shared/menu" menu=$item->getSubmenu()}
</li>
{/foreach}
</ul>
{/if}
There are two methods for creating node in a menu.
$menu->add("Label",$targets_or_url,$options); // creates new menu item and return its submenu (which is at the moment empty)
$menu->addItem("Label",$targets_or_url,$options); // creates new menu item - this new menu item is returned
Breadcrumbs
In a controller:
$breadcrumbs = new Menu14();
$breadcrumbs[] = ["Home","main/index"];
$breadcrumbs[] = ["Articles","articles/index"];
if($tag = $article->getPrimaryTag()){
$breadcrumbs[] = ["$tag",$this->_link_to(["action" => "articles/index", "tag_id" => $tag])];
}
$breadcrumbs[] = $article->getTitle();
$this->tpl_data["breadcrumbs"] = $breadcrumbs;
In a template:
<ol class="breadcrumb">
{foreach $breadcrumbs as $breadcrumb}
<li>
{if $breadcrumb->getUrl()}
<a href="{$breadcrumb->getUrl()}">{$breadcrumb->getTitle()}</a>
{else}
{$breadcrumb->getTitle()}
{/if}
</li>
{/foreach}
</ol>
Check out http://skelet.atk14.net/en/articles/ to see this example live.
Metadata
Metadata can be set on menus or menu items. It may be useful for storing things like colors, images, fade effects...
$menu = new Menu14();
$websites = $menu->add("Frameworks");
$websites->setMeta("image_url","/public/icons/sprockets.png");
$item_atk14 = $website->addItem("Atk14","https://www.atk14.net/",[
"meta" => [
"image_url" => "/public/icons/atk14_birdie.png",
"color" => "black"
]
]);
$item_laravel = $website->addItem("Laravel","https://laravel.com/");
$item_laravel->setMeta("image_url","/public/icons/laravel.png");
$item_laravel->setMeta("color","red");
// getting metadata
$websites->getMeta("image_url"); // "/public/icons/sprockets.png"
$websites->getMeta("color"); // null
$item_atk14->getMeta("image_url"); // "/public/icons/atk14_birdie.png"
$item_atk14->getMeta("color"); // "black"
$item_laravel->getMeta("image_url"); // "/public/icons/laravel.png"
$item_laravel->getMeta("color"); // "red"
Installation
Use the Composer to install Menu14
cd path/to/your/project/
composer require atk14/menu14
Licence
Menu14 is free software distributed under the terms of the MIT license
atk14/menu14 适用场景与选型建议
atk14/menu14 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 43.13k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 08 月 17 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「menu」 「breadcrumbs」 「navigation」 「atk14」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 atk14/menu14 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 atk14/menu14 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 atk14/menu14 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Breadcrumbs integration for Laravel 6
A block to display a list of links to child pages, or pages in current level
A Symfony extension to get active class base on current bundle/controller/action
Navigation bundle for Symfony applications
Laravel Menu management
Control pro Nette Framework usnadňující tvorbu menu a drobečkové navigace
统计信息
- 总下载量: 43.13k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-08-17