I have a module which I want to improve without having to change code inside it to future benefit from updates on that module.
I succeeded into extending the controllers without changing the module’s code(using controllerMap inside module’s config).
I want also to extend a model from that module without having to change module’s code(i.e change module’s class instantiation name inside controllers).
Could you please give me some advice as I didn’t find yet a solution on any of the topics I have read?
I want to add or extend functions to models inside that module and without having to change the module’s code
i.e I have a model named user inside that module and I create an extension of that model named UserExt. Inside UserExt I override one of User’s functions. Now when we call that User’s function inside the module I want it to go to the new function and not use the old one without having to change the instantiations inside the module (meaning using new UserExt instead of new User )
I currently downloaded and installed a module for USER Authentication. It is quite a good module, except that i want to change some minor things in it’s user model, like adding an extra field.
I know I can simply go in the module and edit it, but then I would break upgrade capabilities. I would not benefit anymore of any updates that module has.
Therefore, I want to extend this model, in the same way you can extend a module’s controller, without having to touch any part of the existing code.
Let’s say the module’s model class/file is named User.php …
A wordaround could be to rename it to UserBase.php and create your extended class as User extends UserBase and override whatever you need.
Then in every upgrade you just have to remember to rename that file. I know it’s not the “Right way” to do it, but it’s the only one i could think of right now …
At least that way you don’t need to change any existing module’s code