Answer the question
In order to leave comments, you need to log in
How to use $app->params in models?
In the " Best Practices " section of the official guide, it is written that you should not directly access the session, requests, and environment variables in models. Yii::$app->params
just contains an array of settings / parameters that are related to the environment and sometimes it is very convenient to store various global settings that can be used in the model. For example, apiUrl, some paths for uploading images, etc. And this data needs access directly from the model.
In general, there is no problem, but from the point of view of a competent approach to application design, this is incorrect (in accordance with the official guide).
How to pass these parameters to the model? When initializing the model in the constructor, throw everything? After all, this way you can skip / forget something, or even forget to pass any data to the constructor in some place.
Answer the question
In order to leave comments, you need to log in
Probably, it is worth making a configuration class that will be passed to the model.
We still need to think about compliance with SOLID .
And if you create a helper and work with it? Well, for example .. What will it look like from the point of view of architecture?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question