<p>I know there are similar questions here, but I don't see a definitive answer, nor one that works for me.</p>

<p>I've generated a plugin via pluginfactory.io, which has some controllers and a single service.</p>

<p>I can call the controllers in the CP without issue - if I just return a 'Hello world' from any of the controller methods, it works.</p>

<p>But when I follow the example supplied in the code comments (for the service file) inside of my controller action:</p>

<pre><code>MyPluginName::$plugin-&gt;importer-&gt;exampleService()
</code></pre>

<p>I get an exception:</p>

<blockquote>
  <p>Unknown Property – yii\base\UnknownPropertyException
  Getting unknown property: amphibian\mypluginname\MyPluginName::Importer</p>
</blockquote>

<p>I have a service file called <code>Importer</code> in my <code>services</code> folder, with a class name of <code>Importer</code>, and a method named <code>exampleService()</code>.</p>

<p>The <code>extra</code> section of my <code>composer.json</code> file lists:</p>

<pre><code>"components": {
    "importer": "amphibian\\mypluginname\\services\\Importer"
}
</code></pre>

<p>What else am I missing?</p>

CC BY-SA 4.0
2018-07-26T09:35:02.330Z
Did you change the content of the `composer.json` after you installed the plugin by chance? Maybe you added the service afterwards or change the name of the service? Added this line after you ran `composer update`?
Robin Schambach
CC BY-SA 4.0
2018-07-26T12:33:02.817Z
Based on the info provided, what @RobinSchambach says above is most likely the issue – which means that uninstalling, then re-installing the plugin will probably resolve the issue. I've been bit by this before; it's one of the reasons I'm not a fan of sticking the component config in `composer.json`, I feel that using the [`setComponents()`](https://www.yiiframework.com/doc/api/2.0/yii-di-servicelocator#setComponents()-detail) method from the plugin's `init` method is by far the cleaner option.
Mats Mikkel Rummelhoff
CC BY-SA 4.0
2018-07-26T17:29:40.083Z
Unfortunately, nope - I did no renaming or manual edits. This is happening via files directly downloaded from the plugin generator.
Derek Hogue
CC BY-SA 4.0
2018-07-26T19:16:15.420Z
I'm out of ideas other than if you want to zip up the plugin and attach it so we can try.
Brad Bell
CC BY-SA 4.0
2019-01-04T14:20:22.367Z
Had exactly the same issue with a pluginfactory generated plugin and eventually followed the setComponents instructions here: https://docs.craftcms.com/v3/extend/services.html#creating-a-service
Richard Frank
<plugin-development><craft3><controller><services>
Unable to call a service method from controller in my custom plugin
# Unable to call a service method from controller in my custom plugin

(Asked by: username_0 on 2018-07-25)

I know there are similar questions here, but I don't see a definitive answer, nor one that works for me.
I've generated a plugin via pluginfactory.io, which has some controllers and a single service.
I can call the controllers in the CP without issue - if I just return a 'Hello world' from any of the controller methods, it works.
But when I follow the example supplied in the code comments (for the service file) inside of my controller action:
MyPluginName::$plugin->importer->exampleService()

I get an exception:

Unknown Property – yii\base\UnknownPropertyException
  Getting unknown property: amphibian\mypluginname\MyPluginName::Importer

I have a service file called Importer in my services folder, with a class name of Importer, and a method named exampleService().
The extra section of my composer.json file lists:
"components": {
    "importer": "amphibian\\mypluginname\\services\\Importer"
}

What else am I missing?

**Tags:** plugin-development, craft3, controller, services

> **Comments:**
> **username_1**: Did you change the content of the `composer.json` after you installed the plugin by chance? Maybe you added the service afterwards or change the name of the service? Added this line after you ran `composer update`?  
> **username_2**: Based on the info provided, what @RobinSchambach says above is most likely the issue – which means that uninstalling, then re-installing the plugin will probably resolve the issue. I've been bit by this before; it's one of the reasons I'm not a fan of sticking the component config in `composer.json`, I feel that using the [`setComponents()`](https://www.yiiframework.com/doc/api/2.0/yii-di-servicelocator#setComponents()-detail) method from the plugin's `init` method is by far the cleaner option.  
> **username_0**: Unfortunately, nope - I did no renaming or manual edits. This is happening via files directly downloaded from the plugin generator.  
> **username_3**: I'm out of ideas other than if you want to zip up the plugin and attach it so we can try.  
> **username_4**: Had exactly the same issue with a pluginfactory generated plugin and eventually followed the setComponents instructions here: https://docs.craftcms.com/v3/extend/services.html#creating-a-service  

---

## 0 answers

