Welcome Guest, Not a member yet? Register   Sign In
base controller and base model
#1

[eluser]searain[/eluser]
1) I found that most of my model class have the same lines of codes, cut and paste a lot when I create new model. so a base model approach should be used.

I googled "codeigniter and base model" there are quite a few threads available. Any advices or anyone can share your experience of using base model? Any sample codes you can recommend?

2) For the controllers, it seems base controller should be used for the same reasons too. But controllers are used light weight. So use base controller or not is debatable. What are your advices, experience and recommendations?

3) Any good samples that both use base controller and base model approach and they work together well?

Thanks!
#2

[eluser]Dennis Rasmussen[/eluser]
class MY_Model extends CI_Model {}
class MY_Controller extends CI_Controller {}

Then you just extend MY_Model in your models and MY_Controller in your controllers.
MY_Model and MY_Controller contains shared code/data between all models and controllers.
#3

[eluser]InsiteFX[/eluser]
Ya! if he's using CI 2.0

Otherwise its
class MY_Model extends Model.

InsiteFX
#4

[eluser]Dennis Rasmussen[/eluser]
True dat!
#5

[eluser]searain[/eluser]
Should I use CI 2.0?

I have been using CI for dozens small sites I built up. I upgraded them all to CI 1.7.2 now.

I am thinking about to develop a fresh new framework for my work, use CI as the backbone.

I set up a dev platform on 2.0, and another platform on 1.7.2. Someone said 2.0 is stable, even more stable than 1.7.2. But I cannot see too many doc and support for 2.0 now. And this is for my work. I don't want use 2.0 and be blamed that I pick up an unofficial release if it gives trouble. Plus, I would need to find good 3rd party codes, don't know how many of them out there are for 2.0.

But at the same time, this framework I am developing I would plan to use it for a 2 years range at least. Don't know if I should jump on 2.0 now instead of later on to upgrade it to 2.0 if it is possible within reasonable cost.
#6

[eluser]n0xie[/eluser]
Just use 2.0. There isn't that much different with 1.7.2 except that the latest build removed PHP4 which can only benefit you.




Theme © iAndrew 2016 - Forum software by © MyBB