How to extend an extension object?

If there is an extension that defines a model class that gets used by controllers and view files within the extension, how could I extend this class with Yii means in my application?

E.g. there could be an extension ‘product-management’ that defines a model (ActiveRecord) ‘Product’ that has some basic features. There is a controller with view files. Now in my application I’d like to enrich (that uses the extension) this class with new properties and validation rules, relations and maybe some further functions.

I see here different challenges: Where should the object creation take place? Can I enrich the view files? Can I use the controller in the extension if it does not need to be changed?

Is a factory the right pattern? Could I use behaviours anyhow? Should I override everything in the extension? What would be a sound solution for this issue?

And does the extension need to be prepared for such things?

I hope someone has any hints… Thanks!

Depends on the extension.

Yes. It should be flexible in order to make all the above possible.

Thank you for the feedback!

If the extension has MVC and CRUD code that was created with gii, how far can it be used with regard to overriding? E.g. can I change the view files for the controller in the extension so that view files in the application gets used? Could I change the Model with which the controller deals?

How could I prepare an extension for such a task? Which steps are required for what?

I would think that this is an intersting topic that Yii could support as far as possible (if it not already does): An extension provides some business models and logic that can be adopted to ones own needs easily and flexibly.

I know there are extensions that deal with user management. That is probably a good example for such things: In an application user objects should be extended to have and do more things. Do you know if those extension provide such possibilties? Or are there any other examples?

Gii doesn’t create controller code that could be reused because there’s no sense in re-using CRUDs in most cases. They’re evolving and each one is moving into different direction.

So overall you’ll need to put together a list of what you’d like to be able to change and implement your extension accordingly.

I’d look at themes.

If you build your controller the way that it could deal with any AR model — yes.

User extensions I’ve seen are mostly done in not really flexible way. Ideally your module should define an interface with methods it needs. This interface should be implemented by user model in the application.

Last question: how could I do this and can I benefit from using Yii? Can you provide an example (or a link) with some lines of code?

Check how REST API for AR is implemented. That should give you an idea.