Welcome Guest, Not a member yet? Register   Sign In
[solved] How to create a model class from abstract class
#1

[eluser]Aniket[/eluser]
Hi all,

Creating simple model classes is ok with CI but now suppose i have an abstract base class and a concrete child class extending from base class. Now in CI when we create a model class we extend Model class. But here abstract class is also required to be extended. How should i go about it.
At what level should i extend to Model class ?

Thanks
#2

[eluser]TheFuzzy0ne[/eluser]
Interesting question.

Have you tried creating an abstract MY_Model class? This should work.

EDIT: You should be able to do something like this:

Code:
abstract class MY_Model extends Model {
...
I haven't tested it yet, but I see no reason why it shouldn't work as expected.
#3

[eluser]Aniket[/eluser]
Thanks for reply,
Na.. i haven't tried it yet.

If i am on the right track then if i create MY_Model class then it will extend Model class isn't it ? If yes then the what abt the constructor ?
#4

[eluser]Phil Sturgeon[/eluser]
I don't think you will be able to extend the model class like this.

I'd recommend making your abstract class into a library and loading that before your model extends it. It's either that or a plain PHP include.
#5

[eluser]TheFuzzy0ne[/eluser]
I beg to differ. http://www.oreillynet.com/pub/a/php/2005...tml?page=5. Assuming that really is a valid example, it should work. Smile
#6

[eluser]Aniket[/eluser]
@thefuzzyone

Thanks for the link. I tried it out and it did work. Maybe i need to brushup on my oops concepts....
Thanks once again.
#7

[eluser]TheFuzzy0ne[/eluser]
Glad you got it sorted. I learnt something new today too. Smile
#8

[eluser]Aniket[/eluser]
same here :-)




Theme © iAndrew 2016 - Forum software by © MyBB