Answer the question
In order to leave comments, you need to log in
What is the best way to connect your functionality in yii2?
I want to make a Notifications class that will have 2 public methods, SMS notification, and email notification (wrapper for Yii::$app->mailer), and pull this class when registering, requesting a password, changing user personal data, and so on. What is the best way to connect it to the project? Make a namespace 'services', put this class there, and add it to web.php?
'components' => [
...
'Notifications' => [
'class' => 'app\services\Notifications',
],
...
Answer the question
In order to leave comments, you need to log in
Yes You can create a class, attach it to application components and use it everywhere in the application. But from the point of view of architecture, this is not camelfo, because. such an implementation creates unnecessary dependencies, with all the ensuing disadvantages. It is much better to implement this component on the event system embedded in Yii. Those. roughly speaking, you register in the system, at this moment a corresponding event is generated, and your Notifications class subscribes to this event and does the necessary work
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question