1

I would like to use another plugin from my own plugin. What is the best way to do this. Right now I am doing something like this, but there should be a better way than to explicitly call the service:

Craft::$app->getModule('mobile-detect')->mobileDetectService

What I am really looking for is the service container where I do not have to know anything just the plugin what should have been loaded...?

3

You can call the main plugin class directly

MobileDetect::$plugin->mobileDetectService

I don't know this plugin, maybe the class is wrong but that's the syntax you can use

2
  • Got it, and it will be the same instance I guess right? The "last" thing what I bother to call the service it self ->mobileDetectService... There should be a better way I mean is there any service container what I can call instead? – Visky Máté May 14 '18 at 19:57
  • You instance of the plugin is your service container. Services are components and they are registered in your (singleton) plugin instance. I'm not really sure what you mean by "better" way. – Robin Schambach May 14 '18 at 20:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.