This project is read-only.

Querying Content Manager

Topics: Writing modules
Jul 6, 2011 at 12:35 AM


I am new to orchard.  I am trying to figure out how to do a query from a view from a custom module

I want to create a model that servers as a lookup table.  The table will have 2 fields: cmpnid and phone number.

The module will lookup the url querystring["cmpnid"]  and return the appropriate phone number string.

Any advice would be appreciated. Do I need to create a service in my module?

Jul 6, 2011 at 12:38 AM

Ca you explain the sceanrio with a bit more details? Why do you want to query from the view? Is that a Ajax-style call that you want to do from the client-side?

Jul 6, 2011 at 12:55 AM

I'm not sure how to query the lookup table which will be in the database. Should I create it in a module or create a CampaignPhone content type.

Basically, I want to pass in a campainid via a query string and have the phone number on the page change based on the lookup from the database.

Not sure of the best way to do this in orchard.

Jul 6, 2011 at 1:06 AM

Let me summarize what I understand from the information you gave: you want to have pages on your site that show a phone number from a campaign id that is passed into the url? In other words, you want those phone numbers to have a url?

The simplest seems to be to create a new content type with the routable part and a phone number field. When entering new items of that content type in the admin ui, you can enter that campaign id as the Permalink.

Jul 6, 2011 at 1:24 AM

I dont want them to have a url.  The only thing that will change is the phone number. 

So /about may display an about page with phone number 888.555.5555.  This is the default number

/about?cmpnid=6 will display the same page with phone number 888.666.6666

The phone number may appear on various places on the page.

Jul 6, 2011 at 1:52 AM

Fine then, add a route, write a controller. Where are those numbers stored?

Jul 6, 2011 at 2:26 AM

I wanted to store them in the database.  Should I create a content type?  How do I query it from the view?

Jul 6, 2011 at 6:32 AM

Not necessarily. If you just want to store phone numbers associated with an id, you only need a record. something like PhoneNumberRecord.

About your second question, you should not query from the view (ever). You should query from the controller action and pass the result of that query into the view. The way you would query is by getting a reference to a IRepository<PhoneNumberRecord>. This will give you the methods you need to do the querying.

Jul 8, 2011 at 5:31 PM

Hi Bertrand,

Thanks for all your help. I as able to get it to work, but I had to create a widget in order to do it.

What I would really like to do is insert a shape into the layout without creating a widget in the zone where I want it.

I am not sure how to wire it up in the module / theme.

I want to do something like this.

Is there a way to insert the shape without creating a widget in the zone where I want it?

Thanks for your help in advance. 

Jul 8, 2011 at 6:28 PM

Sure: workContext.Layout.Zones["TheZoneName"].Add(yourShape, "3") where 3 is an arbitrary position I chose that you can change. See