1

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?

3
  • 1
    The object you code for your application logic (business models) are independent to database models in CI or YII. You can re-use data in your models that comes from database models however. Maybe that's the missing link? Commented Oct 4, 2011 at 10:31
  • Just try DooPHP. It dosnt have any major rules witch you have to folow and its easy to maintain. Commented Oct 4, 2011 at 10:34
  • hakre: Please elaborate (I am fairly new to MVC concept), possibly in a form of an answer so I can accept it if its good :). Commented Oct 4, 2011 at 10:56

2 Answers 2

3

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)

Sign up to request clarification or add additional context in comments.

Comments

1

Your question makes sense if one imagines that every framework rolls its own ORM. However I think Symfony had the right idea: integrate with good, separately maintained, ORM systems, so that the core team can concentrate on the framework itself.

So I would look at Propel or Doctrine (both are well-maintained, and both support model inheritance afaik), and then choose your framework based on which offers a good level of integration with your choice of ORM.

1 Comment

Incidentally, although I recommend Symfony, I don't intend to suggest that's your only choice. I believe people have got CI to work with both the ORMs I mention, for example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.