How to create reusable model or controller ?

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?

[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.

extends... mmm, all Models must extends CI_Model, helper, or your own library.

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!

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

A workaround solution is to create a library where you define functions you want to share.
class modelfunctions{
    function modelA_function1()
        return $this->modelA->function1();
     function modelB_function5()
        return $this->modelB->function3();
If you autoload that library you can use those functions you defined in any model you want.
I like this way better than extending models because you have more loose coupling between the models.

wow, tks a million xwero, this is really an great idea

[eluser]Référencement Google[/eluser]
xwero this is very smart! Thanks for sharing this idea.

no problem i get many ideas from looking at other ones solutions so sharing comes natural.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.