Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/digitalwand/yii2-modular-app
API to build modular Yii2 applications
https://github.com/digitalwand/yii2-modular-app
yii2-extension yii2-modules
Last synced: 1 day ago
JSON representation
API to build modular Yii2 applications
- Host: GitHub
- URL: https://github.com/digitalwand/yii2-modular-app
- Owner: DigitalWand
- License: mit
- Created: 2019-11-08T16:35:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-08T17:02:23.000Z (about 5 years ago)
- Last Synced: 2024-12-25T12:12:07.363Z (1 day ago)
- Topics: yii2-extension, yii2-modules
- Language: PHP
- Size: 14.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Yii2 modular application
========================
API to build modular Yii2 applications.Abstract
--------
Yii2 have flexible module system. But if we have project, consists of many modules, we would face this list of problems:
- Every time write boilerplate code to make module controllers work properly and to enable module in config file
- Migrations are project-wide, and you need a bit more code to store migrations into module's code. More boilerplate again.
- Mail templates are project-wide, we also need additional code...
- Module autoloading works only when calling module's controller. But if you module provide only API? We need to control module loading manually.
- Everything mess is possible inside Yii2 module. You have not any strict patterns, how to organise structure.
So, modules from one project might look very different without an evil teamlead
This extension's purpose is to avoid that annoying rakes and make development of modular project more fast and code - more clean and well-structuredInstallation
------------The preferred way to install this extension is through [composer](http://getcomposer.org/download/).
Either run
```
php composer.phar require --prefer-dist digitalwand/yii2-modular-app "*"
```or add
```
"digitalwand/yii2-modular-app": "*"
```to the require section of your `composer.json` file.
Now you should use module's CoreConsoleApplication and CoreWebApplication instead Yii2
Modify you web/index.php to look like this:```php
run();
```and yii file to look like this:
```php
#!/usr/bin/env php
run();
exit($exitCode);
```If everything works like usual, installation is successful!
Creating new modules
--------------------Using Gii is simplest way to start learning and using new module system.
In console try
```shell script
yii gii/strict-module --moduleClass example --moduleID moduleName
```After generation you will see new directory @app/modules/example/moduleName
with controllers, migrations, mail templates and so on, working from the box!Enabling and disabling modules
------------------------------Modules, created this way, could be simply enabled at application's config by special array key:
```php
$config = [
'customModules' => [
'example.moduleName'
]
];
```
No need to provide module's class name, but if you need - you could pass additional module settings like usualModule naming
-------------Keep in mind, that real module name is "moduleName", not "example.moduleName"!
It is critical for `$app->hasModule()` function, for example.The "example" part of module, moduleCalss or moduleNamespace, is simple extension to make your's modules more structured.
But modules with same name but with different namespace will conflict, because Yii see module name only!