PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 3rd, 2012, 12:18 AM
Hall of Famer Hall of Famer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Ithaca
Posts: 64 Hall of Famer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 4 m 57 sec
Reputation Power: 1
About Model and ORM in MVC

Well I've learned quite a bit of MVC pattern thanks to the books I got about Codeigniter and CakePHP. Right now there's one thing I dont quite understand about Model in MVC when it has an ORM system.

Is the concept Model equivalent to Domain Model with ORM? Or is Domain Model just one specific type of Model?

And if so what are the connection of DataMapper and Identity Object with Model? Is DataMapper pretty much a 'factory' object responsible for generating Models?

Sorry for the mess, I am just a bit confused with how ORM works in a MVC framework.

Reply With Quote
  #2  
Old December 3rd, 2012, 12:03 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,791 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
The M in MVC is the data model layer. The data model layer can be whatever you want it to be (assuming it still conforms to the rules of modeling the data and not the business or view), but most people end up using an ORM to model their data.

The Domain Model of ORM is most closely related to the Controller in MVC. When discussing "pure" ORM implementations, there's the Data/Persistence Model and the Domain Model. The Domain Model is one layer "up" from pure data and contains business logic. In MVC, the Controller contains business logic.

Though you could make your Model layer a 2-part layer. Symfony encourages this behavior by having "pure" ORM objects which cannot be altered, as well as having an "override" object where you can put additional business logic which doesn't quite fit in a controller (or needs to be reused a lot).

I'm not even sure what DataMapper is, are you maybe reading from a specific book or website? Both ORM and MVC are patterns, not products. There's no "ORM" thing you can download and get the same "ORM" that everyone else has.

In general, MVC and ORM describe two different things. MVC is a pattern used to develop an entire web app. It describes how to organize the "layers" of your application so that the types of code (data access, business, display) are separate. In MVC, the "Model" layer is simply "how you get to your database."

ORM, on the other hand, describes ONLY how you get to your database. It's one of many patterns of database access. ORM has expanded in definition a bit to include business logic in the objects, which is why you got confused about the Domain Model and how it fits into MVC.
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #3  
Old December 3rd, 2012, 05:20 PM
Hall of Famer Hall of Famer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Ithaca
Posts: 64 Hall of Famer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 4 m 57 sec
Reputation Power: 1
Thanks for such detailed reply, I appreciate it very much. Guess DomainModel is kinda different from the traditional concept of Model, but well even Models in each framework behaves diversely. I wonder how Symfony manages to fit ORM into MVC, the sourcecode of Symfony looks quite complex. I know I do not need to know how its working behind the scene to use a framework properly, but as a PHP programmer I just cant help getting curious. XD

And DataMapper is a special type of object that maps information from relational database to domain model objects. It provides another level of abstraction, although at the cost of significant overhead.

Reply With Quote
  #4  
Old December 4th, 2012, 07:53 AM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,791 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
Quote:
I wonder how Symfony manages to fit ORM into MVC, the sourcecode of Symfony looks quite complex.
Symfony has a very strict MVC, but the Model layer can contain business logic. The layers of Symfony in particular:

- Base data. (5 classes per table) Auto-generated off your database schema and do nothing but access and associate data objects.

- Extended data. (2 classes per table) Auto-generated at first, but then ignored. These classes inherit from the base data tables and allow you to extend functionality to include additional logic for validation, association, dependencies, etc. Some business logic ends up here, though it's technically wrong.

- Controller. (1 class per site module) You can auto-generate a "bundle," which does some of the initial annoying work for you and creates the folder tree, the translation files, the routing file, and other metadata files which aren't PHP, plus an empty controller file. Business logic goes here, as well as the logic for preparing data for the views, processing form posts, validation, etc.

- Views. (1 twig file per page) Twig is very simplistic and can't do much but spit out the data that the controller gave it.

Reply With Quote
  #5  
Old December 4th, 2012, 04:51 PM
Hall of Famer Hall of Famer is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Location: Ithaca
Posts: 64 Hall of Famer User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 4 m 57 sec
Reputation Power: 1
I see, Symfony does look like a quite professional framework, everything is well standardized and mostly automated. I personally dont mind if Model Layer has business logic, this gives them certain degree of flexibility. Thanks for the great summary of Symfony, I guess I understand pretty much how it works now. Still wonder how it does work behind the scene though, but perhaps I aint good enough to interpret everything yet.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > About Model and ORM in MVC

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap