<p>Because that's a Yii event, it doesn't follow the same <code>component.eventName</code> syntax that the other Craft events use and you can't use <a href="http://buildwithcraft.com/classreference/etc/web/WebApp#on-detail" rel="nofollow">craft->on()</a> to register to listen to it.</p>

<p>Completely untested, but you should be able to use the traditional <a href="http://www.yiiframework.com/wiki/327/events-explained" rel="nofollow">Yii method</a>, though. Something like this:</p>

<pre><code>$myRecord-&gt;onAfterDelete = function (Event $event) {
    // Do your thing.
};
</code></pre>

CC BY-SA 3.0
2015-10-21T17:13:53.030Z
It's good to know that craft()->on() won't work, otherwise I probably would've gone crazy trying different things.

So essentially the change would need to be made inside the plugin itself?
John O
CC BY-SA 3.0
2015-10-21T17:54:17.310Z
Yeah, I wasn't clear on whether this one in the context of two plugins or just one.
Brad Bell
CC BY-SA 3.0
2015-10-21T18:12:50.937Z
The delete is occurring within a 3rd party plugin, and I want to be able to tie into that using a plugin we are developing. It sounds like that wouldn't be possible, since the change needs to be made directly in the 3rd party plugin.
John O
CC BY-SA 3.0
2015-10-21T18:20:10.503Z
Yeah, I think you'd need to fork the 3rd party plugin (or make a pull request) to expose that deletion for your plugin to use.
Brad Bell
CC BY-SA 3.0
2015-10-21T16:51:33.563Z
2015-10-21T16:51:33.563Z
Brad Bell
<p>We are using a plugin that has created its own record for storing private messages. When deleting a message, it's calling the <code>delete()</code> method on an instance of the record, which appears to be using the <code>CActiveRecord</code>'s implementation of delete.</p>

<p>In <code>CActiveRecord::delete()</code>, it has a <code>$this-&gt;afterDelete()</code> method, which looks like it should be raising an <code>onAfterDelete</code> event, but I haven't had any luck hooking into it.</p>

<p>I've tried <code>craft()-&gt;on('pluginhandle_messageRecord.onAfterDelete', ...)</code> and <code>craft()-&gt;on('cActiveRecord.onAfterDelete', ...)</code>, but neither gets triggered.</p>

<p>Does anyone know the correct syntax for hooking into this event for this specific custom record?</p>

<p>Thanks!</p>

<events><records><hook>
Hooking into event when record deleted from custom plugin
# Hooking into event when record deleted from custom plugin

(Asked by: username_0 on 2015-10-21)

We are using a plugin that has created its own record for storing private messages. When deleting a message, it's calling the `delete()` method on an instance of the record, which appears to be using the `CActiveRecord`'s implementation of delete.

In `CActiveRecord::delete()`, it has a `$this->afterDelete()` method, which looks like it should be raising an `onAfterDelete` event, but I haven't had any luck hooking into it.

I've tried `craft()->on('pluginhandle_messageRecord.onAfterDelete', ...)` and `craft()->on('cActiveRecord.onAfterDelete', ...)`, but neither gets triggered.

Does anyone know the correct syntax for hooking into this event for this specific custom record?

Thanks!

**Tags:** events, records, hook


---

## 1 answers

### Answer by username_1 on 2015-10-21. Score: 1 | Accepted answer

Because that's a Yii event, it doesn't follow the same component.eventName syntax that the other Craft events use and you can't use craft->on() to register to listen to it.
Completely untested, but you should be able to use the traditional Yii method, though. Something like this:
$myRecord->onAfterDelete = function (Event $event) {
    // Do your thing.
};

> **Comments:**
> **username_0**: It's good to know that craft()->on() won't work, otherwise I probably would've gone crazy trying different things.  So essentially the change would need to be made inside the plugin itself?  
> **username_1**: Yeah, I wasn't clear on whether this one in the context of two plugins or just one.  
> **username_0**: The delete is occurring within a 3rd party plugin, and I want to be able to tie into that using a plugin we are developing. It sounds like that wouldn't be possible, since the change needs to be made directly in the 3rd party plugin.  
> **username_1**: Yeah, I think you'd need to fork the 3rd party plugin (or make a pull request) to expose that deletion for your plugin to use.  

---

