Drivers vs Controllers

Topics: Core, Customizing Orchard, Writing modules
Nov 22, 2011 at 3:47 PM

So, I'm trying to understand the difference between Drivers and Controllers. My need is this:

I need to create a module that queries datatables that are not mapped by Orchard/NHibernate. I understand a little about how to go about this.

I also understand I can create a separate MVC 3 app in VS and then drop it into Orchard as a module and have it display the results on the page.

However I need to go through the process of publishing the page from the Admin UI. They select the Product ID from a drop down, and publish the page. The query will pull other information needed based on the ProductID key and display the data using a ViewModel and view.cshtml.

 

I need this module to work on every page that is published. If I use controllers isn't a controller page specific? In other words, ( and correct me if I am wrong ), for every page I want to publish it needs it's own Controller? i.e. homecontroller, indexcontroller, productdetailcontroller?

Whereas in Orchard it seems I only need 1 Driver and it displays the information no matter how many different pages of products I create. Again I may not know enough about how Controllers work.

Should I bypass the Driver altogether and just use an old fashioned Controller?

But I only want to write 1 Controller for every page that is published. Or do I need the Driver in order to publish from the Admin UI?

 

I hope this makes sense.

 

Oceantrain

Nov 22, 2011 at 4:02 PM

A controller can display many pages, it depends how you set up your routes. You can route {*path} to your controller action if you like, but then you'd need to set up a mapping from the path to your content.

Really you can do what you're after either way. The question you need to ask is: are you showing content? If you're showing content, then you should try and use Orchard's Content system. You could even set up an import process to map your existing data to something that fits into Orchard's content model, otherwise you're creating what is probably a difficult situation for yourself.

It sounds like all you actually want is some kind of ProductPart and a "Product" content type, so you can create product content and still take advantage of Orchard's content extensibility.

Nov 22, 2011 at 4:32 PM

Yeah you are right. Thats pretty much what I want to do. Is there any way of mapping my custom tables to orchard with out just creating new tables and transferring/migrating the data from one table to another? How can tell Orchard "Hey, these tables with their schemas also belong to NHibernate."

It's important that the schemas remain intact. No new ID columns or new primary keys. Just the ones that were originally in place.

 

I really do want orchards content extensibility. Thats why I'm using it.

 

Oceantrain.

Nov 22, 2011 at 8:01 PM

Thanks Pete. You mentioned:

"You could even set up an import process to map your existing data to something that fits into Orchard's content model, "

 

How can I map to my existing data without creating new tables in Orchard and without touching the original schema of the tables? This where I am stuck. Is there something in the migrations file?

I know there is a method to CreateTable, but what does AlterTable do? Or is there a MaptoTable method of somekind?

 

Thanks

 

Oceantrian