Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yidas/yii2-nav-locator
Yii 2 Navigation Routing Locator for active menu identification
https://github.com/yidas/yii2-nav-locator
controller locator navigation router yii2 yii2-extension
Last synced: about 2 months ago
JSON representation
Yii 2 Navigation Routing Locator for active menu identification
- Host: GitHub
- URL: https://github.com/yidas/yii2-nav-locator
- Owner: yidas
- License: mit
- Created: 2018-10-17T06:56:51.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2018-12-11T07:43:53.000Z (about 6 years ago)
- Last Synced: 2024-10-11T05:21:20.489Z (3 months ago)
- Topics: controller, locator, navigation, router, yii2, yii2-extension
- Language: PHP
- Homepage:
- Size: 72.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yii 2 Navigation Locator
Yii 2 Navigation Routing Locator for active menu identification
[![Latest Stable Version](https://poser.pugx.org/yidas/yii2-nav-locator/v/stable?format=flat-square)](https://packagist.org/packages/yidas/yii2-nav-locator)
[![Latest Unstable Version](https://poser.pugx.org/yidas/yii2-nav-locator/v/unstable?format=flat-square)](https://packagist.org/packages/yidas/yii2-nav-locator)
[![License](https://poser.pugx.org/yidas/yii2-nav-locator/license?format=flat-square)](https://packagist.org/packages/yidas/yii2-nav-locator)FEATURES
--------- *Smartly **identifying active navigation** on current controller action*
- *Multi-validators for **grouping active navigation***
- *Route **prefix setting** support*
---
OUTLINE
-------* [Demonstration](#demonstration)
* [Requirements](#requirements)
* [Installation](#installation)
* [Usage](#usage)
- [is()](#is)
- [in()](#in)
- [setPrefix()](#setprefix)---
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
Data
Data Centers
```
- 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
```php
public static boolean is(string $route)
```
*Example:*
Suppose `site/index` as the current controller action:
```php
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
```php
public static boolean in(string $route)
```
*Example:*
Suppose `site/index` as the current controller action:
```php
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
```php
public static self setPrefix(string $prefix)
```
*Example:*
```php
Data
Data Centers
```
> You could call it without parameter for reset prefix: `\yidas\NavLocator::setPrefix()`