I am trying to migrate a project into an MVC framework (deciding between CI and Yii).
Now, I have, for the sake of argument, two objects, text and image, which I would like to build based on an object class.
Parent:
class Object() extends Somemodel{
protected $x;
protected $y;
protected $page;
...
methods()...
}
And children:
class Image() extends Object{
protected $width;
protected $height;
...
methods()...
}
class Text() extends Object{
protected $text;
protected $font;
...
methods()...
}
Now as I understand this is a nice approach becasue some common functions like getting x/y coordinates etc. will be placed in the Object while all specific things will be placed in the children classes.
I was hoping to have one table in the database to store the Object.
However frameworks are giving me hard time to try and make it work… which makes me think, that probably I am doing something wrong, because if everyone was doing it like this then, I suppose, frameworks would support that easily.
Any thoughts?
You should not be doing this. You are violating Liskov Substitution principle (quick picture to explain it), which basically says that you should be able to replace instance of any child class , with instance of parent class.
P.S. this is only my opinion , but i would warn you away from both of the frameworks you mentioned. They both have major design flaws and other issues. (if you want details, visit php chat room .. no point in flaming here)