Hello.

There was such a dilemma: In the module there is public $email = 'test@test.test'

In the config / main I connect this module, but I don’t change this value in the configs, then, in the view I need, the following code occurs:

 $email = "myEmail@email.email"; $myModule = \Yii::$app->getModule('myModName'); $myModule->email = $email; 

On the module side there is a controller with this piece of code:

 Yii::$app->mailer........->setTo($this->module->email)->...... 

The essence of the problem: I was at the entrance to test@test.test email, and it remains so on the controller, although I seem to change the value of the property above.

What am I wrong in that the module controller does not see the new value in the end?

  • Is the controller code from the module executed immediately after changing $ email in the view? Or before or in another request? More detail please what is caused by what. What kind of module controller is that kind of view? - Anton Rybalko
  • @AntonRybalko Runs in another request: There is just a view on the front, where I initialize the module ==> it draws the form, and the AJAX request sends the data to your SaveController - Alex Khonko

1 answer 1

This line changes the emial only for the current module instance in the current request.

 $myModule->email = $email; 

In the view you need to add an email to the form (for example, hidden input) and explicitly send an email SaveController AJAX request to SaveController