A module for CRM - Drivers and Controllers

Topics: Customizing Orchard, General, Writing modules
Apr 16, 2011 at 12:31 AM

Hi,

This is a follow up on a previous post, http://orchard.codeplex.com/discussions/254127 I have digged deeper into the code and now am a bit confused on when to use a Driver or a Controller?

Some examples (Bing.Maps) use a ContentPartDriver and the others (Contrib.Profile) that use a controller/route approach, I'm failing to understand the diferences between both aproaches, since both appear to display and edit Content Parts?

Many thanks for you help in advance,

Pedro Costa

Coordinator
Apr 16, 2011 at 12:40 AM

Well, no, a controller does not edit content parts. That's what drivers do and it is pretty much it: for parts, use drivers, for everything else use controllers.

Apr 18, 2011 at 10:49 AM

Ah, ok I think I'm getting the zest of it! There's so much info, that is a bit daunting to get to grips with it in just a few days :)

What I didn't notice was that the controllers were rendering a shape that invokes @Display for it's Model, which would then call the drivers for each of the parts ta constitute the ProfilePart.

With that, I did come across @Display(New.Profile_Head(ContentItem: Model.ContentItem)) in http://orchardprofile.codeplex.com/SourceControl/changeset/view/cc7339aef63f#Views%2fHome%2fIndex.cshtml

Could you explain what New.Profile_Head is doing? Am I correct in assuming it is invoking a Shape with the name Profile_Head?

Apr 19, 2011 at 12:10 AM
Edited Apr 19, 2011 at 12:15 AM

Yes, it's building a shape. It maps to the Profile.Head.cshtml file. Other modules could hook into this event by implementing IShapeTableProvider and by a few other methods, to add their own shapes or alter that one.

Your second statement was slightly incorrect - when @Display(Model) is called, what's happening is that the Model is a shape that's already been built by drivers and other extension points.