Hi Marco!
I apologize for not having replied sooner; I've been on vacation this week with very limited internet access.
I'm assuming you're using MiServer 2.1. MiServer 3.0 will be available later this year, and makes some minor naming changes.
Templates - Every page has to eventually derive from the MildPage class (in MiServer 3.0 it will be the MiPage class).
So, your class hierarchy should be like: helloworld >> ABC >> MildPage
Here's a very simple example. The only thing the ABC template does is set the title for the page.
But you can see where helloworld derives from ABC which derives from MildPage
Code: Select all
:Class helloworld : ABC
∇ html←Render req
:Access Public
html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
∇
:EndClass
:Class ABC : MildPage
:Include #.HTMLInput
∇ Wrap req;head
:Access Public
head←'head' Enclose req.Response.HTMLHead,'title' Enclose 'Testing'
req.Response.HTML←'html' Enclose head,'body' Enclose req.Response.HTML
∇
:EndClass
Where to put the APL script files that make up your MiSite...In the sample MiSites, we've used a convention of having a \Scripts folder which is intended for JavaScript files, not APL script files. However, there's no requirement for you to use that convention; you can organize your MiSite however works best for you.
Historically, we've located MiSites under the MiServer folder - the sample MiSite "Intro" is located in the \Intro folder under the MiServer root folder. However, it's probably best to locate your MiSite(s) in a separate folder not under the MiServer root. This will make it easier to update MiServer in the future, and separates your code from the code that Dyalog supplies. So, you could potentially have something like:
C:\MiSites\MiSite1
C:\MiSites\MiSite2
C:\MiSites\YetAnotherMiSite
Then, when you start your MiSite1, you'd use
Start 'C:\MiSites\MiSite1'
Style SheetsSimilar to \Scripts, we've used a convention in the sample MiSites to locate style elements (CSS file, images, etc) in the \Styles folder. Again, you can organize your MiSite however works best for you.
To use the request object's Style method, you'd do something like this:
Code: Select all
:Class helloworld : ABC
∇ html←Render req
:Access Public
req.Style '\Styles\yellow.css'
html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
∇
:EndClass
APL/OOP and MiServerI'm not sure I have enough information on the structure and use of your application to give you a definitive answer on this.
For example, is there a separate instance of your file class per file, per user, or something else?
I'll try to lay out some options here that might give you an idea of how to proceed.
If we need to dig deeper in the specifics of your application, we may want to move that discussion to email rather than in the forums.
- Your classes need not be saved as APL script files (though there are a lot of good reasons to do so). You could save the workspace with your classes, copy the contents of the mserver workspace, and set up a ⎕LX to perform whatever initialization needed to be done and then start your site.
- If you do save your classes in APL script files, you can have the code called by ⎕LX do a ⎕SE.SALT.Load to bring in each class.
- If your need an instance of your class for each user, MiServer creates a session for each user which will persist until the session times out or the server is shut down. For something like this, you could test to see if the class has been initialized and take some appropriate action.
Here's some mocked up code that does that sort of thing.
Code: Select all
:Class mypage : ABC
:Field initialized←0 ⍝ start out as not initialized
∇ html←Render req
:Access Public
:If ~initialized
myinstance←⎕NEW #.myclass ⍝ create the instance
initialized←1 ⍝ and indicate that we've initialized
:EndIf
req.Style '\Styles\yellow.css'
html←'h2' #.HTMLInput.Enclose'Welcome to MiServer!'
html,←'div' #.HTMLInput.Enclose myinstance.readdata ⍝ use the instance
∇
:EndClass
I hope this helps. These are all good questions - keep them coming!
/Brian