Best Way to Add Classes?

I needed to create my own class library so that I could reuse my code. What’s the best way to do this in Yii 2?

Is there another way to do this? I think extension is overkill, I just need a separate class file which I’m going to call from my controller.


Yep, just write a class.

Save it somewhere in your projects directoy (for example "components").

Give it a namespace.

Use the namespace / class in your controller.

There is no magic "Yii specific thing" in this…


Thanks! That’s a relief to hear :)