Custom Yii2 component folder in Craftcms?


I have built a custom component in a standalone install of Yii2. The component is non-assets set of classes for calculations. The component works fine. We run Craftcms and I would like to move the component to a proper location. Is there a way to have my custom components under a components folder in the Craft base path?

I’ve searched posts and can’t even locate how to add components to Craft… unless they are modules.


The best practice is to use a module and place your components there unless you want to extend craft itself (which is basically a yii2 module as well) and use your own app logic in order to call/create your own files from whereever you want.

Besides that you can add controllers/controller maps in your config/app.php to include a starting point. But in generell I would always suggest to include your code in craft cms via module (or plugin but those are modules as well)

Thank you for your response! I tried as a module, but I could not keep it from trying to perform an action/request. As I mentioned, this is only non-visual, set of calculation classes. I did it in Yii because I like the ActiveRecord and common database features of the framework. I know I’m missing something basic. In my component, I only have 2 folders (Entities & Services). The entities folder has all the AR classes. The services contains all the actual calculation classes, etc.

Is that something I can convert into a module? I would assume I need a module class and the config info in my app.php? Do you have a sketch/skeleton?

In my Module config, could I just reference my main entry class in the services folder instead of having a .php file? Forgive my ignorance.

How do I call a singleton method in a custom module?