Answer the question
In order to leave comments, you need to log in
YII2: How to get module settings in controller?
Hello. I'm making a file upload module. I want to make the save folder customizable when the module is connected:
'modules' => [
'image' => [
'class' => 'common\modules\image\Image',
'folder_image' => '/uploads/image_news',
'folder_image_preview' => '/uploads/image_news_preview',
],
],
common/modules/image/Image.php
I specify these "variables"public $folder_image;
public $folder_image_preview;
$file->saveAs(Yii::getAlias('@frontend') . '/web/uploads/' . $filename);
Answer the question
In order to leave comments, you need to log in
Good afternoon.
If you specify a property in the model, then you need to access it like this:
public $filename;
$model = new Image();
$model->filename;
'main' => [
'class' => 'app\modules\main\MainModule',
'layout' => 'main.php',
'layoutPath' => '@app/modules/main/views/layouts',
'params' => [
'test' => 'test1',
'test2' => 'test22'
]
],
// Если указали в классе модуля public $filename
$main = Yii::$app->getModule('main');
echo $main->filename;
// Если указали параметром в конфигурационном файле.
$main = Yii::$app->getModule('main');
echo $main->params['test'];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question