-2

Next semester we'll learn the mvc pattern in web development but since it looks pretty interesting to me i decided to learn it now but...there is a problem. Surfing trough the pages i found two approaches to the mvc pattern(in php):

ONE

One

TWO

Two

Now my question is which one is the right approach? (and is there any guide that you can poin me to?)

Thank you!:D

  • The 'MVC' pattern is an overloaded term which means different things to different people, but both are 'correct' in their own way. The second diagram looks to be illustrating MVC in a client-side app, whereas the first is illustrating the pattern as used by web services to serve web content. There is also an added complexity that the term 'Model' is also overloaded - in the first example, "model" means "the rest of the app", but in the second example it usually means "An object containing view data". The first diagram is closer to PHP, but MVC usually has a view data 'model' as well. – Ben Cottrell Jan 27 at 21:41
  • oky, thank you @BenCottrell, i'll go with the first one then, looks easier :D – emma Jan 28 at 10:30
1

In my opinion, both the diagram seem to show the same thing, but not with the same appearance. What is important when starting with the MVC architectural pattern is to really separate all of the parts :

  • Controller : It is often the entry point for the request. There are more and implementation where there is a routing middleware not included inside the controller. But as all the guide and books will tell you, the controller is where you'll spend most of your time
  • Model : The model is sometimes mixed with the ORM. The purpose of the model is only to be the center of the data of your application. In almost all implementation, the model is closely tied to the ORM, and sometimes we have one model for each table / document type.
  • View : The view can be as simple as you want it. The important part is to remember that you should never put logic inside your View. Logic = Controller. The only thing you should put in your views are datas, markup and the minimal amount of code to make it work. A lot of implementation of views use template engine to allow a small amount of logic to be used in the view without using a full fledged programming language.

All in one, when teaching web dev, my students found quite interesting to create (with help of course), a small MVC framework to try and see how it works.

There is no definitive guide that I know of, but using, for example, a small framework like Tiny MVC as a boilerplate has yielded good results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.