承接 yidas/yii2-nav-locator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

yidas/yii2-nav-locator

Composer 安装命令:

composer require yidas/yii2-nav-locator

包简介

Yii 2 Navigation Routing Locator for active menu identification

README 文档

README

Yii 2 Navigation Locator


Yii 2 Navigation Routing Locator for active menu identification

Latest Stable Version Latest Unstable Version License

FEATURES

  • Smartly identifying active navigation on current controller action

  • Multi-validators for grouping active navigation

  • Route prefix setting support

OUTLINE

DEMONSTRATION

Giving a 3-layer controller action route structure for Yii 2 framework:

yii2/
├── controllers/           
    ├── data/      
        ├── ListController.php
        └── StructureSettingController.php
    ├── datacenters/            
        ├── ClusterSettingController.php
        └── ListController.php
    └── SiteController.php      

In the view of global navigation menu, write active conditions by Nav Locator:

<?php
use yidas\NavLocator as Locator;
use yii\helpers\Url;
?>

<li class="treeview <?php if(Locator::in('data/')):?>active menu-open<?php endif ?>">
  <a href="#">
    <i class="fa fa-database"></i> <span>Data</span>
    <span class="pull-right-container">
      <i class="fa fa-angle-left pull-right"></i>
    </span>
  </a>
  <ul class="treeview-menu">
    <li class="<?php if(Locator::in('data/list')):?>active<?php endif ?>"><a href="<?=Url::to(['data/list'])?>"><i class="fa fa-circle-o"></i> Data List </a></li>
    <li class="<?php if(Locator::in('data/structure-setting')):?>active<?php endif ?>"><a href="<?=Url::to(['data/structure-setting'])?>"><i class="fa fa-circle-o"></i> Structure Setting </a></li>
  </ul>
</li>

<li class="treeview <?php if(Locator::in('datacenters/')):?>active menu-open<?php endif ?>">
  <a href="#">
    <i class="fa fa-server"></i> <span>Data Centers</span>
    <span class="pull-right-container">
      <i class="fa fa-angle-left pull-right"></i>
    </span>
  </a>
  <ul class="treeview-menu">
    <li class="<?php if(Locator::in('datacenters/list/')):?>active<?php endif ?>"><a href="<?=Url::to(['datacenters/list'])?>"><i class="fa fa-circle-o"></i> Node List </a></li>
    <li class="<?php if(Locator::in('datacenters/cluster-setting/')):?>active<?php endif ?>"><a href="<?=Url::to(['datacenters/cluster-setting'])?>"><i class="fa fa-circle-o"></i> Cluster Setting </a></li>
  </ul>
</li>

  • Example 1 active URI: data/list, data/list/action
  • Example 2 active URI: data/structure-setting, data/structure-setting/action
  • Example 3 active URI: datacenters/list, datacenters/list/action
  • Example 4 active URI: datacenters/cluster-setting, datacenters/cluster-setting/action

Nav Locator even supports route rule mapping. If you have a rule 'test' => 'data/list', the Nav Locator could identify as in data/list when you enter with test route.

REQUIREMENTS

This library requires the following:

  • PHP 5.4.0+
  • Yii 2.0.0+

INSTALLATION

Install via Composer in your Yii2 project:

composer require yidas/yii2-nav-locator

USAGE

is()

Validate current controller action is completely matched giving route

public static boolean is(string $route)

Example:

Suppose site/index as the current controller action:

use yidas\NavLocator as Locator;

Locator::is('site');            // False (Route `site` could not refer to a actual action)
Locator::is('site/');           // False (There is no difference between using a slash or not)
Locator::is('site/index');      // True  (Successfully match the same controller ID and same action ID)
Locator::is('site/index/');     // True 
Locator::is('site/other');      // False (Failed to match the same controller ID but the different action ID)
Locator::is('site/other/');     // False 

The giving route need to be defined precisely, the format is module-ID/controller-ID/action-ID.

in()

Validate current controller action is under giving route

public static boolean in(string $route)

Example:

Suppose site/index as the current controller action:

use yidas\NavLocator as Locator;

Locator::in('site');            // True  (Current route `site/index` is indeed in `site` layer)
Locator::in('site/');           // True 
Locator::in('site/index');      // True  (Current route `site/index` is indeed the `site/index` layers)
Locator::in('site/index/');     // True 
Locator::in('site/other');      // False (Current route `site/index` is not in `site/other` layers)
Locator::in('site/other/');     // False 
Locator::in('si');              // False (Current route `site/index` is not in `si` layer, `site` != `si`)
Locator::in('si/');             // False 
Locator::in('site/index/index');// False (This route means `site` module with `index` controller and `index` action)

The giving route will divide into independent and precise route layers by each separator, letting you distinguish whether the current controller action belongs to the parent navigation.

setPrefix()

Set prefix route for simplifying declaring next locator routes

public static self setPrefix(string $prefix)

Example:

<?php
use yidas\NavLocator as Locator;
?>

<li class="treeview <?php if(Locator::setPrefix('data/')->in('/')):?>active menu-open<?php endif ?>">
  <a href="#">
    <i class="fa fa-database"></i> <span>Data</span>
    <span class="pull-right-container">
      <i class="fa fa-angle-left pull-right"></i>
    </span>
  </a>
  <ul class="treeview-menu">
    <li class="<?php if(Locator::in('list/')):?>active<?php endif ?>"><a href="<?=Url::to(['data/list'])?>"><i class="fa fa-circle-o"></i> Data List </a></li>
    <li class="<?php if(Locator::in('structure-setting/')):?>active<?php endif ?>"><a href="<?=Url::to(['data/structure-setting'])?>"><i class="fa fa-circle-o"></i> Structure Setting </a></li>
  </ul>
</li>

<li class="treeview <?php if(Locator::setPrefix('datacenters/')->in('/')):?>active menu-open<?php endif ?>">
  <a href="#">
    <i class="fa fa-server"></i> <span>Data Centers</span>
    <span class="pull-right-container">
      <i class="fa fa-angle-left pull-right"></i>
    </span>
  </a>
  <ul class="treeview-menu">
    <li class="<?php if(Locator::in('list/')):?>active<?php endif ?>"><a href="<?=Url::to(['datacenters/list'])?>"><i class="fa fa-circle-o"></i> Node List </a></li>
    <li class="<?php if(Locator::in('cluster-setting/')):?>active<?php endif ?>"><a href="<?=Url::to(['datacenters/cluster-setting'])?>"><i class="fa fa-circle-o"></i> Cluster Setting </a></li>
  </ul>
</li>

You could call it without parameter for reset prefix: \yidas\NavLocator::setPrefix()

yidas/yii2-nav-locator 适用场景与选型建议

yidas/yii2-nav-locator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 74 次下载、GitHub Stars 达 2, 最近一次更新时间为 2018 年 11 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「extension」 「navigation」 「helper」 「locator」 「yii」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 yidas/yii2-nav-locator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 yidas/yii2-nav-locator 我们能提供哪些服务?
定制开发 / 二次开发

基于 yidas/yii2-nav-locator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 74
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-20