S
S
Snewer2016-06-22 15:43:38
Yii
Snewer, 2016-06-22 15:43:38

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

2 answer(s)
Кирилл Арутюнов, 2016-06-22
@Snewer

Если в vendor хотите хранить, то упаковывайте все свои классы как расширение и подключайте его через composer.
Если вы используете эти классы только в 1 проекте, то разместите их в любом месте (например, папка Components), настройке неймспейсы и подключайте их в нужных местах приложения.
Не забывайте, что папка vendor находится в gitignore и в git её не будет (а значит и класса вашего там не будет).

S
Snewer, 2016-06-22
@Snewer

Issue with command controllers resolved: no aliases were specified

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question