2

I created a plugin for Craft 3 at pluginfactory.io.

I want to call it in my template variable

public function exampleVariable()
{

    // hint   AdminBar::$plugin->editLinks->exampleService()
    //$result = FacebookPageConnector::$plugin->eventsService->fetchEvents();
      $result =  FacebookPageConnector::$plugin->facebookPageConnectorEventsService->exampleService();

    //$result = FacebookPageConnector::$plugin->eventsService->fetchEvents();
    return $result;
}

But whatever I try to name my service, I get an exception like this:

Getting unknown property: boscho87fbconnector\facebookpageconnector\FacebookPageConnector::facebookPageConnectorEventsService

What are the correct naming conventions?

I saw an example here: https://github.com/wbrowar/craft-3-adminbar/blob/master/src/services/EditLinks.php#L48, but this did not work for me.

But when I call the predefined service from the pluginfactory: FacebookPageConnector::$plugin->facebookPageConnectorService->exampleService(), it works fine .

here images with my code

enter image description here

enter image description here

2

In your plugin's composer.json, add the service to extra.components to make it available on the plugin instance. You should see the predefined service already listed there.

You might need to empty the vendor folder of your craft website and reinstall your composer dependencies as Craft appears to cache this information.

1

It's hard to say for sure without seeing your plugin code, but my guess is you have a myplugin\serivces\FacebookPageConnectorService.php file/class defined, but not a myplugin\services\FacebookPageConnectorEventsService.php file/class defined.

6
  • i have a FacebookPageConnectorEventsService.php file – Simon Müller Mar 2 '17 at 20:11
  • What's the name of the class in that file? – Brad Bell Mar 2 '17 at 21:47
  • Same like filname but without php – Simon Müller Mar 2 '17 at 22:31
  • Php shows be de class icon so this should be ok, i also tried to crate a new plugin in the pluginfactory with the same name an created the serviceclass. But this class does work neeither, sorry for my bad english 🙈 – Simon Müller Mar 2 '17 at 22:33
  • Is FacebookPageConnector the name of your plugin, or are you calling another plugin from within yours? Maybe it'd help if you posted a screenshot of the directory/file structure of your plugin. – Brad Bell Mar 3 '17 at 0:34
0

Just came across this issue with pluginfactory.io plugin scaffold.

Turns out that the service method name was only called when starting with a lowercase. Not clear enough if it applies here but might help someone.

2
  • Are you saying there is something wrong with the scaffolding code on pluginfactory.io ? I'm pretty sure it's correct...? – andrew.welch Jul 2 '18 at 15:39
  • No - on digging further the composer.json file was specifying service names in the extra components section. – joomkit Jul 2 '18 at 18:27

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.