Download the PHP package bmsrox/yii2-module-autoloader without Composer

On this page you can find all versions of the php package bmsrox/yii2-module-autoloader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package yii2-module-autoloader

YII2 Module AutoLoader

INSTALL

composer require bmsrox/yii2-module-autoloader

or

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

HOW TO USE

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

config.php

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

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.


All versions of yii2-module-autoloader with dependencies

PHP Build Version
Package Version
Requires yiisoft/yii2 Version ~2.0.4
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package bmsrox/yii2-module-autoloader contains the following files

Loading the files please wait ....