Simple question: when can I call my site to have "MVC"?

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

Post Reply
User avatar
aditya2071990
Forum Contributor
Posts: 106
Joined: Thu May 22, 2008 11:30 am
Location: Hyderabad, India
Contact:

Simple question: when can I call my site to have "MVC"?

Post by aditya2071990 »

I tried various resources on the web trying to learn the ropes on stuff like architecture and design in code, but they have a frustrating habit of assuming I have knowledge of all the fancy jargon they prefer to employ while explaining stuff...

Anyways, from what I understood, it seems that MVC means that all the "data" the site has to deal with is called Model, all the visual interface of the site is in "view", and the php code that runs these together is in Controller; :? sorry, but is that not how every site works? Have all the data in the MySQL database, all the view is handled by the php code within the script, and the rest of the HTML in the script takes care of the view stuff!

So, where is my assumption wrong? And please be an angel and point to me a resource, book, blog, article or website or whatever that discusses this stuff in detail, while taking care to explain difficult-to-define terms before they use them...
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Re: Simple question: when can I call my site to have "MVC"?

Post by alex.barylski »

Anyways, from what I understood, it seems that MVC means that all the "data" the site has to deal with is called Model, all the visual interface of the site is in "view", and the php code that runs these together is in Controller; sorry, but is that not how every site works?
The gist of the idea, yes. It can get a lot more detailed though.

Every application is modeled after MVC -- whether all the PHP/HTML/SQL/JS/CSS is in one monolithic file or not, but the separation of concerns is more distinct in some applicaitons that others.
Have all the data in the MySQL database, all the view is handled by the php code within the script, and the rest of the HTML in the script takes care of the view stuff!
The model is just that (not strictly the data) -- it's a virtual representation of the problem you are trying to solve. Whether you store your "user" records in a database or XML file is only of interest to the data access layer (if you even have one).

Software should be built in layers, preferably which are totally independent of others, but usually it's acceptable to have the higher layer being dependent on the lower layer, but the reverse is generally accepted as a bad practice.
So, where is my assumption wrong? And please be an angel and point to me a resource, book, blog, article or website or whatever that discusses this stuff in detail, while taking care to explain difficult-to-define terms before they use them...
There is no single point of reference or resource that will give you that "aha" moment...it comes with time and experience and debating with others on this site and others. Read about other design patterns, not just MVC, study frameworks (as many as you can). Each promotes different and similar or related practices, etc.
User avatar
aditya2071990
Forum Contributor
Posts: 106
Joined: Thu May 22, 2008 11:30 am
Location: Hyderabad, India
Contact:

Re: Simple question: when can I call my site to have "MVC"?

Post by aditya2071990 »

Thank you for the informative response :)

But even you couldn't resist the temptation to use jargon when you said:
The model is just that (not strictly the data) -- it's a virtual representation of the problem you are trying to solve. Whether you store your "user" records in a database or XML file is only of interest to the data access layer (if you even have one).
:D

But thanks for letting me know that going advanced isn't it as easy as learning the basics... it is common sense yes, but sometimes, one loses that too :)
Post Reply