PHPackages                             mohannad/active-state - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mohannad/active-state

Abandoned → [mohannadnaj/active-state](/?search=mohannadnaj%2Factive-state)ArchivedPackage[Utility &amp; Helpers](/categories/utility)

mohannad/active-state
=====================

Helper Package for marking active state in application's runtime.

1.0.0(8y ago)013MITPHPPHP &gt;=5.3

Since Aug 3Pushed 8y ago1 watchersCompare

[ Source](https://github.com/MohannadNaj/active-state)[ Packagist](https://packagist.org/packages/mohannad/active-state)[ Docs](https://github.com/mohannadnaj/active-state)[ RSS](/packages/mohannad-active-state/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (2)Used By (0)

active-state
============

[](#active-state)

PHP Helper Package for marking active state in application's runtime.

Common use cases for this package includes: Marking the active menu-item, Marking the active item in your Navbar, Sidebar, or Tabs.

[![Total Downloads](https://camo.githubusercontent.com/102700ffae28ac70513e16afa765683d4e46f18134ac581251021f3223b38cc6/68747470733a2f2f706f7365722e707567782e6f72672f6d6f68616e6e61646e616a2f6163746976652d73746174652f646f776e6c6f616473)](https://packagist.org/packages/mohannadnaj/active-state)[![Build Status](https://camo.githubusercontent.com/1f7d5811934a7d0b2e7f9cff3488afd14ac782d9df24748e93aef261689740c8/68747470733a2f2f7472617669732d63692e6f72672f4d6f68616e6e61644e616a2f6163746976652d73746174652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MohannadNaj/active-state)

---

Installation:
-------------

[](#installation)

### Composer:

[](#composer)

The preferred installation method, using [composer](https://getcomposer.org/download/) the package is available at [Packagist](https://packagist.org/packages/mohannadnaj/active-state) so it can be required:

```
composer require mohannadnaj/active-state

```

---

Usage:
------

[](#usage)

### Basic:

[](#basic)

```
    set_active('navbar', 'index');
    set_active('sidebar', 'info');

    is_active('navbar','index'); // return "active"
    is_active('navbar','about'); // return null

    is_active('sidebar','info'); // return "active"
    is_active('sidebar','warning'); // return null

    get_active('navbar'); // return 'index';
    get_active('sidebar'); // return 'info';

```

### Return Custom string other than the default 'active' string:

[](#return-custom-string-other-than-the-default-active-string)

```
    set_active('navbar2', 'index',['true'=>'some-active-css-class']);

    is_active('navbar2','index');    // return 'some-active-css-class'
    is_active('navbar2','about');    // return null

```

### Return Custom string on success/failure:

[](#return-custom-string-on-successfailure)

```
    set_active('navbar3', 'register',['true'=>'is-active-css-class', 'false'=> 'not-active']);

    is_active('navbar3', 'register'); // return 'is-active-css-class'
    is_active('navbar3', 'login'); // return 'not-active'

```

### Without Key:

[](#without-key)

```
    set_active('developer-mode');

    is_active('developer-mode');  // return 'active'
    is_active('not-developer-mode');  // return null

    get_active();  // return 'developer-mode'

```

### Return Boolean:

[](#return-boolean)

```
    set_active('bottom-bar', 'index',['return'=>'boolean']); // 'boolean' or 'bool'

    is_active('bottom-bar','index');    // return true;
    is_active('bottom-bar','about');    // return false;

```

### Get The Active Item:

[](#get-the-active-item)

```
    set_active('tabs', 'tab2');

    get_active('tabs'); // return 'tab2';

```

---

What's inside
-------------

[](#whats-inside)

### Problem:

[](#problem)

Marking an active item is a common essential part in any UI, providing a visual indication of the state of an item. This is commonly used in PHP like:

```
$current_page = 'contact';
