1

I'm getting this error when trying to call my plugin on a template:

Fatal error: Call to undefined method Craft\SiteUtilitiesService::init() in /path/to/my/site/craft/app/framework/base/CModule.php on line 394

The template tag:

{{ craft.siteUtilities.videoEmbed( block.video, '219181' ) }}

Content of variables/SiteUtilitiesVariable.php:

class SiteUtilitiesVariable
{
    public function videoEmbed($url, $color)
    {
        return craft()->siteUtilities->videoEmbed($url, $color);
    }
}

Content of services/SiteUtilitiesService.php:

class SiteUtilitiesService
{
    public function videoEmbed($url, $color)
    {
        // some code to get the video ID from the $url variable

        return "<some html embed code with the $color variable>";
    }
}

What's the init method the error is referencing?

  • 1
    Stab in the dark, but if your main plugin class file extending BasePlugin? – Brad Bell Dec 12 '15 at 1:00
  • @BradBell I actually wasn't extending BaseApplicationComponent in the Services file. – kmgdev Dec 12 '15 at 1:04
  • Ahh, that's what I meant to say. :) Would you mind adding that as an official answer? – Brad Bell Dec 12 '15 at 1:10
3

I needed to extend BaseApplicationComponent in my Services file:

class SiteUtilitiesService extends BaseApplicationComponent
{
    public function videoEmbed($url, $color)
    {
        // some code to get the video ID from the $url variable

        return "<some html embed code with the $color variable>";
    }
}

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.