CodeIgniter Forums

Full Version: Inheritance in codeigniter
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Aji[/eluser]
I am new to codeigniter. I want to know whether inheritance or polymorphism is used in codeigniter?If yes,can any one explain how it is?

El Forum

[eluser]richthegeek[/eluser]
Yes, just as it is in all PHP programs.

With regards to inheritance itself, you can extend the controller or model base class (see "Extending Core" in guide) and libraries as well.

For polymorphism, you probably want to create a model that acts as the factory and include the target classes in the same file for creation by the model-extending class.

El Forum

[eluser]Aji[/eluser]
Thank you for your quick reply richthegeek.
So you said for polymorphism,i have to include the necessary classes in a model,right?

El Forum

[eluser]richthegeek[/eluser]
You don't have to, but otherwise you'd have to load them by other means (includes etc) which can be a bit of a PITA for no gain.

El Forum

[eluser]Aji[/eluser]
thank you for your help and hope you will continue in future