You are not logged in.
Pages: 1
Hi,
I am trying to find out how to make a web application with mORMot MVC, by trying out sample 30 and going through the documentation.
The findings of my journey I am putting in this forum so members can comment on. Please do not regard any questions as dumb as I am just trying
to get a clear picture of the workings of the framework.
I hope to create a how-to from this thread so others can also benefit from, in their mORMot journey and is not meant as a replacement of the SAD :-)
What I have understood so far is, in order to make a mORMot MVC webapp one needs to:
- create the Model. The model inherits from TSQLModel and comprises of TSQLRecord classes as described in the documentation 'Framework Software Architecture Design'.
- create the ViewModel/Controller:
- define an interface inherited from IMVCApplication. The methods of this interface comprises the actions/functionalities of the webapp.
- when a method passes data to a HTML (template)file the name of this HTML (template)file must be the same as the method. (is this Case Sensitive??)
- create a class to implement the interface. This class must be derived from TMVCApplication.
- When not passing any data (through parameters) to the views for page rendering, one can use the methods GotoView/GotoError/GotoDefault to populate
a TMVCAction record for rendering by an appropriate View. These methods are class methods in TMVCApplication.
- create the View:
- create HTML (template)files that represents the Views of the webapp. These template files must reside in a folder called Views.
In these HTML files, Mustache tags are incorporated so the mORMot Mustache implementation can generate the appropriate HTML webpages
for the user of the webapp.
- Mustache tags in a template file corresponds to the parameters of the interface method that implements the action/functionality of the webapp.
- use web design software to create the views.
- create the 'plumbings' of the server:
- create the Database.
- create the REST server from TSQLRestServer. This REST server is started by the ViewModel/Controller.
- create the HTTP server.
Questions:
- In sample 30, ORM TSQLRecord classes are tightly incorporated. I think using the ORM is the most efficient way, but is it possible not to use the
ORM? When not using ORM to pass data to Mustache, JSON can be used to pass the data? This goes also for data being submitted from the Views?
- To create a mORMot MVC webapp, at least one need to? (feel free to complement this list):
- know how to read data submitted from the Views.
- know how to pass data to the Views
- understand how to glue together the Model, Database, TSQLRestServer and TSQLHttpServer
- know some HTML
Thank you all for your patience and any constructive feedback is much appreciated.
Cheers,
Wai
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
Nice abstract!
About the question, you could return the JSON directly, e.g. using TDocVariantData. But the data has to come from somewhere... You could use plain SQL, but ORM gives you very good speed and, via the variant published fields, implements easily the notion of "aggregate"; of course, as I stated in the documentation, using a dedicated persistence service (behind an interface) will be a cleaner way to go, if the project becomes complex.
Offline
Merci, Arnaud.
fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...
Offline
Pages: 1