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?

http://www.yiiframework.com/doc-2.0/guide-structure-extensions.html

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.

Hi,

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…

Regards

Thanks! That’s a relief to hear :)