How to create reusable model or controller ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to create reusable model or controller ? (/showthread.php?tid=3459) |
How to create reusable model or controller ? - El Forum - 10-02-2007 [eluser]Wades[/eluser] Hi guys, after using CI for developing several websites, I really love this framework. and now I'd like to make it more flexible, so I want to make some reusable models or controller. What I want to do is that: suppose there are two models: A_model and B_model then there is a function in A_model called function_a(); so how could I use function_a() of A_model in B_model? Is anybody can help me? How to create reusable model or controller ? - El Forum - 10-02-2007 [eluser]Référencement Google[/eluser] Why not that B extends the A model? Not quiet sure we can extend models with others but give it a try. How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]imzyos[/eluser] extends... mmm, all Models must extends CI_Model, helper, or your own library. How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]Wades[/eluser] thanks elitemedia, I've tried this way, yes, B can extends A model, but if there is another base model C, then B also wants to use the functions in C, then is there any way to get this work? I want to make it something like java, when you want to use a class, then just import it and then it can be used. anyone who has this kind of experience in CI? thank you! How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]Luci3n[/eluser] PHP5 can only extend one class, you will need to create a generic class which extends the the base model class then after extend the generic class See this thread How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]xwero[/eluser] A workaround solution is to create a library where you define functions you want to share. Code: class modelfunctions{ I like this way better than extending models because you have more loose coupling between the models. How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]Wades[/eluser] wow, tks a million xwero, this is really an great idea How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]Référencement Google[/eluser] xwero this is very smart! Thanks for sharing this idea. How to create reusable model or controller ? - El Forum - 10-03-2007 [eluser]xwero[/eluser] no problem i get many ideas from looking at other ones solutions so sharing comes natural. |