Models in Symfony2, and other MVC frameworks?

model, model-view-controller, oop, php, symfony

Solution

Symfony2 does not have the traditional "Model" part of MVC like other frameworks do. Even Entities/Documents from ORM/ODM Doctrine are not part of the framework itself nor does Symfony2 depend on it.

As Fabien (creator of Symfony framework) wrote on his blog,

"It's up to you to create your model by hand or use any other tool, like an ORM" ... "I don't like MVC because that's not how the web works. Symfony2 is an HTTP framework; it is a Request/Response framework."

It was hard for me to understand just reading, but I understood what he meant when I actually started programming in Symfony2.

A service in Symfony2 on the otherhand is just an object that performs a global task. Router, doctrine, logger, mailer are some of the many services that come preloaded with Symfony2. You can access services from any part of your code.

Symfony2 services are completely different from web services. Symfony2 services are meant to be used within your system while web services are meant to be used from machine to machine via REST api for example. Although, I guess you could create RESTful api as part of your service.

Problem

I'm trying to understand how Models work in proper MVC. As far as I know, Models in MVC is where the application logic happens, Models are meat, or back bone of MVC. Views are just presentation, and Controllers are "glue" that asks Models to do some actions, return some data, and pass that information to the View that is presented to the user. Now, I'm exploring all kinds of different MVC frameworks and would like to understand how to use models in MVC. Symfony 2 is interesting framework as far as Models goes, since there are no Models :) I have problems grasping some of the features of Symfony2, and where does Models fit in Symfony2 MVC. By definition, Models are where domain logic, and database actions goes. So my questions are: - In Symfony2 we have Entities, and Services, are those two Models in Symfony? - What is the difference in Symfony2 Services, and Web Services? So my questions are where is the Model in Symfony2? Since Model is a layer, composed of Domain Objects, and Data Mappers, then I can assume that Entities are Domain Objects, and Doctrine is Data Mapper, is that correct? And where do Symfony2 services fit in?

Original source