<p>I needed to extend <code>BaseApplicationComponent</code> in my Services file:</p>

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

        return "&lt;some html embed code with the $color variable&gt;";
    }
}
</code></pre>

CC BY-SA 3.0
2015-12-12T01:16:40.657Z
2015-12-12T01:16:40.657Z
kmgdev
<p>I'm getting this error when trying to call my plugin on a template:</p>

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

<p>The template tag:</p>

<p><code>{{ craft.siteUtilities.videoEmbed( block.video, '219181' ) }}</code></p>

<p>Content of <code>variables/SiteUtilitiesVariable.php</code>:</p>

<pre><code>class SiteUtilitiesVariable
{
    public function videoEmbed($url, $color)
    {
        return craft()-&gt;siteUtilities-&gt;videoEmbed($url, $color);
    }
}
</code></pre>

<p>Content of <code>services/SiteUtilitiesService.php</code>:</p>

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

        return "&lt;some html embed code with the $color variable&gt;";
    }
}
</code></pre>

<p>What's the <code>init</code> method the error is referencing?</p>

CC BY-SA 3.0
2015-12-12T01:00:09.143Z
Stab in the dark, but if your main plugin class file extending BasePlugin?
Brad Bell
CC BY-SA 3.0
2015-12-12T01:04:21.037Z
@BradBell I actually wasn't extending `BaseApplicationComponent` in the Services file.
kmgdev
CC BY-SA 3.0
2015-12-12T01:10:05.337Z
Ahh, that's what I meant to say. :)  Would you mind adding that as an official answer?
Brad Bell
<plugin-development>
Call to Undefined Method ::init Error
# Call to Undefined Method ::init Error

(Asked by: username_0 on 2015-12-12)

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 "";
    }
}

What's the init method the error is referencing?

**Tags:** plugin-development

> **Comments:**
> **username_1**: Stab in the dark, but if your main plugin class file extending BasePlugin?  
> **username_0**: @BradBell I actually wasn't extending `BaseApplicationComponent` in the Services file.  
> **username_1**: Ahh, that's what I meant to say. :)  Would you mind adding that as an official answer?  

---

## 1 answers

### Answer by username_0 on 2015-12-12. Score: 3 | Accepted answer

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 "";
    }
}


---

