<p>Kind of, but probably not what you're looking for.</p>

<p>Your plugin can certainly do a <code>MyAssetFileModel extends AssetFileModel</code> and (in the scope of your plugin) take advantage of existing <code>AssetFileModel</code> methods and properties and override them as needed.  But that's the catch... it will only be within the executing scope of your plugin.</p>

<p>There's no native way (without hacking core Craft files) to tell Craft "use <code>MyAssetFileModel</code> wherever you would normally use <code>AssetFileModel</code>".</p>

<p>However, this is certainly much more doable in the upcoming Craft 3 release since Yii 2 has native support for things like service locators and dependency injection.</p>

CC BY-SA 3.0
2016-05-15T01:25:54.983Z
Yeah, I had a feeling that was the case. Appreciate the help!
kroppian
CC BY-SA 3.0
2016-05-15T00:53:24.763Z
2018-05-01T05:13:26.717Z
2018-05-01T05:13:26.717Z
Brad Bell
<p>I'm new to Craft and PHP, so thanks ahead of time!</p>

<p>Is it possible to override a model method with a plugin? For example, I want to add some additional functionality to the <code>getUrl</code> method of the <code>AssetFileModel</code> class. Can this be done in a plugin?</p>

<p>Thanks!</p>

CC BY-SA 3.0
2016-05-15T05:21:05.427Z
As Brad mentioned below, you're probably headed in the wrong direction here... You might want to join [Craft Slack](https://craftcms.com/community#slack) and pose that question to the community. You'll probably get some great answers for how to better tackle your problem!
Lindsey D
<plugins><models>
Override a model method via plugin
# Override a model method via plugin

(Asked by: username_0 on 2016-05-14)

I'm new to Craft and PHP, so thanks ahead of time!

Is it possible to override a model method with a plugin? For example, I want to add some additional functionality to the `getUrl` method of the `AssetFileModel` class. Can this be done in a plugin?

Thanks!

**Tags:** plugins, models
> **Comments:**
> **username_1**: As Brad mentioned below, you're probably headed in the wrong direction here... You might want to join [Craft Slack](https://craftcms.com/community#slack) and pose that question to the community. You'll probably get some great answers for how to better tackle your problem!  

---

## 1 answers

### Answer by username_2 on 2016-05-15. Score: 3 | Accepted answer

Kind of, but probably not what you're looking for.

Your plugin can certainly do a `MyAssetFileModel extends AssetFileModel` and (in the scope of your plugin) take advantage of existing `AssetFileModel` methods and properties and override them as needed. But that's the catch... it will only be within the executing scope of your plugin.

There's no native way (without hacking core Craft files) to tell Craft "use `MyAssetFileModel` wherever you would normally use `AssetFileModel`".

However, this is certainly much more doable in the upcoming Craft 3 release since Yii 2 has native support for things like service locators and dependency injection.

> **Comments:**
> **username_0**: Yeah, I had a feeling that was the case. Appreciate the help!  

---

