Yii2 Boot Modules

How can I load an external site module? I have a common module that I need to download on different Yii2 sites, for example, in an advanced template. My idea is to have a shared directory that stores shared modules that I can upload to each site. The file system structure may be as follows: / site-1/ (loads modules from common-modules dir for site-1) site-2/ (loads modules from common-modules dir for site-2) common_sites_modules/ module-1/ module-2/ carrello/ Carrello.php

Each site in its configuration should load modules from common-modules/ Is it possible to implement this structure?

Change 1

Configuration:

'cart' => [ 'class' => dirname(dirname(dirname(__DIR__))) . '/common_sites_modules/carrello/Carrello', 'params' =>[ ... ], 'components' => [ ... ], ],

and this is the first line of the Carrello.php class:

<?php namespace common_sites_modules\carrello; ...

The top line of the editor with the class outline and the error returned by Yii: Sublime top bar

enter image description here

Edit 2:

Thanks to @Yupik for support and offers new settings:

bootstrap.php:

Yii::setAlias('@common-modules', dirname(dirname(dirname(__DIR__))) . '/common_sites_modules');

main local.php:

'class' => '@common-modules\carrello\Carrello',

Error generated:

enter image description here

, , . @Yupik, common/config/bootstrap.php :

Yii::setAlias('@common_modules', dirname(dirname(dirname(__DIR__))) . '/common_modules');

:

'carrello' => [ 'class' => ''common_modules\carrello\Carrello', ... ]

, .

+4

Source: https://habr.com/ru/post/1681712/


All Articles