PHPackages                             bmsrox/yii2-module-autoloader - 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. bmsrox/yii2-module-autoloader

ActiveYii2-extension

bmsrox/yii2-module-autoloader
=============================

Extension to autoload modules dynamically

v1.1.1(8y ago)61.4k3[1 PRs](https://github.com/bmsrox/yii2-module-autoloader/pulls)BSD-3-ClausePHP

Since Nov 30Pushed 3y ago2 watchersCompare

[ Source](https://github.com/bmsrox/yii2-module-autoloader)[ Packagist](https://packagist.org/packages/bmsrox/yii2-module-autoloader)[ Docs](https://github.com/bmsrox/yii2-module-autoloader)[ RSS](/packages/bmsrox-yii2-module-autoloader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (0)

YII2 Module AutoLoader
======================

[](#yii2-module-autoloader)

### INSTALL

[](#install)

```
composer require bmsrox/yii2-module-autoloader

```

or

```
"bmsrox/yii2-module-autoloader":"dev-master"

```

### HOW TO USE

[](#how-to-use)

Create a module in your app and add config.php in the module root path

#### config.php

[](#configphp)

```
use app\modules\admin\AdminModule;

return [
    'id' => 'admin',
    'class' => AdminModule::className(),
    'urlManagerRules' => [
        '/admin' => '/admin/default/index'
    ]
];

```

Set the components in your web.php or main.php.

```
'components' => [
        ...
        'moduleLoader' => [
            'class' => 'bmsrox\autoloader\ModuleLoader',
            'modules_paths' => [
                '@backend/modules',
                '@frontend/modules',
                '@common/modules'
                ]
        ],
        ...
 ]

```

PS: If you are using a basic template the default modules\_paths is @app/modules. but you can specify any path.

Set the bootstrap as

```
'bootstrap' => [
    ...
    'moduleLoader'
    ...
 ],

```

### Using Events

[](#using-events)

Example to use a events

I've been created an event called SidebarMenu to add menu dynamically when i create a new module.

```
use yii\base\Component;

class SidebarMenu extends Component {

    const REGISTER = 'register';

    private $items = [];

    public function init() {
        $this->trigger(self::REGISTER);
        return parent::init();
    }

    public function setItem($item) {
        if (!isset($item['sortOrder']))
            $item['sortOrder'] = 1000;
        $this->items[] = $item;
    }

    public function getItem() {
        $this->sortItems();
        return $this->items;
    }

    /**
     * Sorts the item attribute by sortOrder
     */
    private function sortItems() {
        usort($this->items, function ($a, $b) {
            if ($a['sortOrder'] == $b['sortOrder']) {
                return 0;
            } else
            if ($a['sortOrder'] < $b['sortOrder']) {
                return - 1;
            } else {
                return 1;
            }
        });
    }

}

```

Create a class Events in your module root path like

```
    use yii\base\Object;
    use yii\helpers\Html;

    class Events extends Object {

        public static function onMenuRegister($event) {
            $event->sender->setItem([
                'label' => 'example',
                'url' => ['/example/default/index'],
                'visible' => !Yii::$app->user->isGuest,
                'sortOrder' => 2
            ]);
        }

    }

```

In your module/config.php add a key into array config

```
    'events' => [
        ['class' => SidebarMenu::className(), 'event' => SidebarMenu::REGISTER, 'callback' => [Events::className(), 'onMenuRegister']],
    ],

```

Call the Menu class to render a dynamic menu

```
        echo Menu::widget([
            'items' => (new \app\components\SidebarMenu())->getItem(),
        ]);

```

So you can add many events into your module that it will be added automatically.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~249 days

Total

3

Last Release

2947d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/80df76dabb01dfc4f5a035f5e0efeedd21f37e91fe1bac969d07998b0ebcd043?d=identicon)[bmsrox](/maintainers/bmsrox)

---

Top Contributors

[![bmsrox](https://avatars.githubusercontent.com/u/3869640?v=4)](https://github.com/bmsrox "bmsrox (6 commits)")[![cboulanger](https://avatars.githubusercontent.com/u/75390?v=4)](https://github.com/cboulanger "cboulanger (3 commits)")

---

Tags

autoloadyii2extensionmodulesbmsrox

### Embed Badge

![Health badge](/badges/bmsrox-yii2-module-autoloader/health.svg)

```
[![Health](https://phpackages.com/badges/bmsrox-yii2-module-autoloader/health.svg)](https://phpackages.com/packages/bmsrox-yii2-module-autoloader)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k46](/packages/skeeks-cms)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
