I want to use third party module in my several projects on yii. For example module comments https://github.com/segoddnja/Comments-module
Usually need to do some changes in module for specific project. If i need to use costom views, I will just copy them in to theme and modify. How can I override method from php class, that located in module? For example I want to modify method in model class. How can I do that?
Thanks in advance
If you use this comments module repo a lot, but it seems that it just isn't the way you like (or need) it, then fork it!
Fork the repo, and edit the code the way you like it. Only you know how you need it to work. Add in your own custom functions, your own helpers, completely chop up the existing functions to work the way you want.
Remember, with OOP, your focus is reuse-ability. Create classes and functions that you can use on future projects.
If you have a function you use every time, but for 1 out of 10 projects you need to change it, then extend it. You can Extend your Class and override the function. So the only thing that would change, would be you would add in a new Class that extends your existing one, and ONLY has those few functions you need to override.
To extend it, You would just create a new file, in components as someone said. Unless you jacked up your main config, all files in the components dir are autoloaded. Just make sure the name of the file is the same as the class!
Just look at your CommentsModule for example. They extend CWebModule. CommentsModule has all the functions and variables that CWebModule has, but can have more functions/variables, or override ones defined in CWebModule. It essentially hijacked it.
Class CommentsModule Extends CWebModule{}