Reputation: 381
I've got a problem I haven't been able to get my head around. I'm working on my own web app framework in php. I know there's plenty of good stuff out there but I like to play around with this and I'm not using it for any sensitive production stuff.
So here's the problem: I have an abstract base class which contains some functions that I want all of the models to inherit. There's also an abstract base controller which extends the base model with functions for basic manupulation. Currently, all created models extend the base model and all controllers extend the base controller. So, all controllers also inherit from the Base model through the Base controller. But now I have no access to model properties from the model controller since models extend the Base controller and it seems weird for models to extend the Base controller.
How should I set this so that I can have access to the model properties from their respective controller?
Thanks!
Upvotes: 0
Views: 88
Reputation: 58444
To begin with, it would seem to me, that your understanding of what is Model .. well .. is bad. Maybe this comment would help a bit.
The other thing, which seems wrong which whole picture is this:
So, all controllers also inherit from the Base model through the Base controller.
You should avoid deep inheritance. And since Controllers and What-You-Call-Models have completely different responsibilities, there should nothing inherited by both. You must understand that extends
is a synonymous with is-a
.
If you write class Admin extends User
, then it means that every admin is a user. This also means that, when you write class User extends Table
, it is wrong (.. and kinda insulting).
Controller should not read properties from what-you-call-model (assuming you are not implementing MVP pattern instead). That part should be done by View, since that would be the part, responsible for presentation logic.
And to for that you what-you-call-model should have specific getters. You should never exposed properties directly (as in, setting them public
), because then you would be breaking encapsulation.
.. my 3 cents
Upvotes: 2