How to set up a unique class of module in yii-2? Interested in the option without creating in the GII system.
This is a class that inherits from yii\base\Module
An example of how this class might look like:
namespace app\modules\forum; class Module extends \yii\base\Module { public function init() { parent::init(); $this->params['foo'] = 'bar'; // ... ΠΎΡΡΠ°Π»ΡΠ½ΠΎΠΉ ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·ΠΈΡΡΡΡΠΈΠΉ ΠΊΠΎΠ΄ ... } }
Question: What exactly should the init()
function do?
Here is another option to customize this class:
If the init () method has become too cumbersome because of the code that sets the properties of the module, these properties can be saved as a configuration and then loaded into the init () method as follows:
public function init() { parent::init(); // ΠΈΠ½ΠΈΡΠΈΠ°Π»ΠΈΠ·Π°ΡΠΈΡ ΠΌΠΎΠ΄ΡΠ»Ρ Ρ ΠΏΠΎΠΌΠΎΡΡΡ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΈ, Π·Π°Π³ΡΡΠΆΠ΅Π½Π½ΠΎΠΉ ΠΈΠ· config.php \Yii::configure($this, require(__DIR__ . '/config.php')); }
At the same time in the configuration file config.php there may be the following code similar to the configuration of the application:
<?php return [ 'components' => [ // ΡΠΏΠΈΡΠΎΠΊ ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠ°ΡΠΈΠΉ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½ΡΠΎΠ² ], 'params' => [ // ΡΠΏΠΈΡΠΎΠΊ ΠΏΠ°ΡΠ°ΠΌΠ΅ΡΡΠΎΠ² ], **];
Question: What exactly should there be - components
and params
?