Download the PHP package digitalwand/yii2-modular-app without Composer
On this page you can find all versions of the php package digitalwand/yii2-modular-app. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digitalwand/yii2-modular-app
More information about digitalwand/yii2-modular-app
Files in digitalwand/yii2-modular-app
Package yii2-modular-app
Short Description API to build modular Yii2 applications
License MIT
Informations about the package yii2-modular-app
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-structured
Installation
The preferred way to install this extension is through composer.
Either run
or add
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:
and yii file to look like this:
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
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:
No need to provide module's class name, but if you need - you could pass additional module settings like usual
Module 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!