MVC - Controller and Model in the same class?

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: MVC - Controller and Model in the same class?

Post by josh »

Technical wrote:Finally, I've come with acceptable and good(I think) solution.
So I made Item and Set classes.
Then, I made

Code: Select all

ContentItem extends Item
and

Code: Select all

ContentSet extends Set
.
Content class is a View.

For example,

Code: Select all

$Item = new ContentItem(1); // Item with ID 1
Content::Item($Item);

$Set = new ContentSet(0, 10); // 10 items
Content::Items($Set);
Thanks everyone for help, I see now that MVC is really better and more useful
You created a controller & models. There is no view that I can see, which makes it 2 tier and not MVC. I'm presuming that you separated display & business logic at the method level instead of the class level.

I never said there's anything wrong with your code, just that its not MVC.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MVC - Controller and Model in the same class?

Post by Christopher »

josh wrote:You created a controller & models. There is no view that I can see, which makes it 2 tier and not MVC. I'm presuming that you separated display & business logic at the method level instead of the class level.
The sense I get is that the Content class (called statically) is the View class and then example shown is the Controller ... but Technical would have to verify that.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: MVC - Controller and Model in the same class?

Post by josh »

Ah, well in that case there is a problem with his code. It is MVC but its using bad naming. It should be called View, not Content (especially since it coincides with a model name)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MVC - Controller and Model in the same class?

Post by Christopher »

Yep.
(#10850)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: MVC - Controller and Model in the same class?

Post by John Cartwright »

Good software engineers deliver. Bad software engineers deliver excuses. Try to avoid working with people that aren't as passionate or capable with a project as yourself.

//back into shadows
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: MVC - Controller and Model in the same class?

Post by Christopher »

Yeah agreed ... this is yet another "I came in contact with the concept X when I joined a team ... therefore concept X is bad" posts.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: MVC - Controller and Model in the same class?

Post by josh »

That post originally had spam links. Its not even a real person. :roll: Why the mods kept it there I don't know, they are too kind.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: MVC - Controller and Model in the same class?

Post by Benjamin »

josh wrote:That post originally had spam links. Its not even a real person. :roll: Why the mods kept it there I don't know, they are too kind.
I didn't see it but he's gone now. That post was actually from a post or comment on reddit.com. Weird.
Post Reply