DNN Forums

Ask questions about your website to get help learning DNN and help resolve issues.

Module developing

 6 Replies
 4 Subscribed to this topic
 26 Subscribed to this forum
Sort:
Author
Messages
New Around Here
Posts: 3
New Around Here

Hi, I want to develop a module that needs a setting in PortalSettings table. In the installing script I want to insert the row but how can I specify the current PortalId in which the module is being installing?

Thanks in advance.

Veteran Member
Posts: 1246
Veteran Member
MVP
MVP
You're an MVP!
When a module is installed or upgraded, there is no reference to a portal. So I'm not sure that you can do something like this.

What is the use case here?
New Around Here
Posts: 0
New Around Here

As Joe states there is no 'current' portal when installing a module - but if you 'just' need a valid portal id you can fetch the first available. Fill in the rest of the fields as needed - and remember to take the database scheme into consideration (the curly brackets part).

[code]

INSERT INTO {YourDatabase}.{dbo}.[PortalSettings]
           ([PortalID]
           ,[SettingName]
           ,[SettingValue]
           ,[CreatedByUserID]
           ,[CreatedOnDate]
           ,[LastModifiedByUserID]
           ,[LastModifiedOnDate]
           ,[CultureCode]
           ,[IsSecure])
     VALUES
           ((SELECT TOP (1) [PortalID] FROM {YourDatabase}.{dbo}.[Portals] ORDER BY [PortalID])
           ,@SettingName, nvarchar(50),
           ,@SettingValue, nvarchar(max),
           ,@CreatedByUserID, int,
           ,@CreatedOnDate, datetime,
           ,@LastModifiedByUserID, int,
           ,@LastModifiedOnDate, datetime,
           ,@CultureCode, nvarchar(10),
           ,@IsSecure, bit,)

 [/code]

New Around Here
Posts: 3
New Around Here

Hi Joe,

thanks for the answer. I wanted to give an initialize value to a portalsettings for my module, but, if I have no references to the current Portal, I can do what DnnBro suggested.

Thanks.

Veteran Member
Posts: 1182
Veteran Member
MVP
MVP
You're an MVP!

I would just do something like

<code>// This is pseudocode, not c#!<br /> protected string DefaultValueForMyModule {<br />    get {<br />       object o = PortalController.GetPortalSetting(PortalId, "DefaultValueForMyModule");<br />       if (o == null) {<br />          return "DefaultValue";<br />       }<br />       return o.ToString();<br />    }<br /> }</code>

Happy DNNing!
Michael

 

Michael Tobisch
DNN★MVP

DNN Connect
Growing Member
Posts: 45
Growing Member
try this.portalid you will get the portal id for the current DNN running portal.
3ART TechnologiesRegards,
3ART Technologies Expert

3ART Technologies
Experts in Analysis, Design & Development for DNN and SharePoint Solution
https://www.3art.tech/
Senior Member
Posts: 1607
Senior Member
MVP
MVP
You're an MVP!
New Poster
New Poster
Congrats on posting!

You can use a technique like this:  

https://github.com/hotcak...troller.cs#L381-L390

You should just be aware that DNN instances that contain thousands of portals exist.  Anytime this is the case, such a technique might not be the best way to do this.  

These Forums are for the discussion of the open source CMS DNN platform and ecosystem.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. If you have (suspected) security issues, please DO NOT post them in the forums but instead follow the official DNN security policy
  2. No Advertising. This includes the promotion of commercial and non-commercial products or services which are not directly related to DNN.
  3. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  4. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  5. No Flaming or Trolling.
  6. No Profanity, Racism, or Prejudice.
  7. Site Moderators have the final word on approving / removing a thread or post or comment.
  8. English language posting only, please.

Would you like to help us?

Awesome! Simply post in the forums using the link below and we'll get you started.

Get Involved