Answer the question
In order to leave comments, you need to log in
How to store custom classes in Yii2?
Hello!
There is some class used for parsing information from a third party service. Where should it be stored and how should it be used? Where to store the class configuration and how to apply it?
Now the vendor folder has its own folder (say, mytest) with the test.php class in which it is specified. namespace mytest
In web controllers, an new /mytest/test()
instance of the class is created using the class instance, but the same does not work in command controllers. What could be the problem? Throws an error that the /mytest/test class was not found.
Thank you!
Answer the question
In order to leave comments, you need to log in
Если в vendor хотите хранить, то упаковывайте все свои классы как расширение и подключайте его через composer.
Если вы используете эти классы только в 1 проекте, то разместите их в любом месте (например, папка Components), настройке неймспейсы и подключайте их в нужных местах приложения.
Не забывайте, что папка vendor находится в gitignore и в git её не будет (а значит и класса вашего там не будет).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question