Answers.Body: <p><strong>myHelpers_Post.savePos</strong>t was wrong. It should have been <strong>myHelpers_<em>p</em>ost.savePost</strong>. It's okay to delete this question.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-06T07:56:24.890Z
Answers.Text: It's good to keep the question in, in case someone else comes across a similar problem. Just accept your own answer as the correct one!
Answers.UserDisplayName: KSP
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-05T12:44:35.630Z
Answers.LastActivityDate: 2017-08-05T12:44:35.630Z
Answers.UserDisplayName: Anya Dit
Body: <p>I have some questions about events. I want to fire a custom event from another plugin. The event handler is in <strong>MyHelpers_PostService.php</strong> (plugin A).</p>
  
  <pre><code>public function onSavePost(Event $event)
  {
      $this-&gt;raiseEvent('onSavePost', $event);
  }
  </code></pre>
  
  <p>My init() method (plugin B):</p>
  
  <pre><code>public function init()
  {
      craft()-&gt;on('myHelpers_Post.savePost', function(Event $event)
      {
         // delete a cache key 
         craft()-&gt;pluginB-&gt;clearCache('forum-home-desktop');
      });
  }
  </code></pre>
  
  <p>This is my first time working on Craft events, so please bear with me. I tested this by saving a new Helpers Post on the front-end and nothing happens. </p>
  
  <p>The <strong>clearCache()</strong> method is just using Craft's <strong>deleteCachesByKey()</strong>;</p>
  
  <ol>
  <li>Is <strong>myHelpers_Post.savePost</strong> correct?</li>
  <li>What else do I need to make this work?</li>
  <li>How do I test this properly? Can I use Craft::dd() inside the handler?</li>
  </ol>
  
Tags: <events>
Title: How to fire a custom event from another plugin?
ThreadText: # How to fire a custom event from another plugin?
  
  (Asked by: username_0 on 2017-08-05)
  
  I have some questions about events. I want to fire a custom event from another plugin. The event handler is in **MyHelpers\_PostService.php** (plugin A).
  
  ```
  public function onSavePost(Event $event)
  {
      $this->raiseEvent('onSavePost', $event);
  }
  
  ```
  
  My init() method (plugin B):
  
  ```
  public function init()
  {
      craft()->on('myHelpers_Post.savePost', function(Event $event)
      {
         // delete a cache key 
         craft()->pluginB->clearCache('forum-home-desktop');
      });
  }
  
  ```
  
  This is my first time working on Craft events, so please bear with me. I tested this by saving a new Helpers Post on the front-end and nothing happens.
  
  The **clearCache()** method is just using Craft's **deleteCachesByKey()**;
  
  1. Is **myHelpers\_Post.savePost** correct?
  2. What else do I need to make this work?
  3. How do I test this properly? Can I use Craft::dd() inside the handler?
  
  **Tags:** events
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-08-05. Score: 1 | Accepted answer
  
  **myHelpers\_Post.savePos**t was wrong. It should have been **myHelpers\_*p*ost.savePost**. It's okay to delete this question.
  
  > **Comments:**
  > **username_1**: It's good to keep the question in, in case someone else comes across a similar problem. Just accept your own answer as the correct one!  
  
  ---
  
  