#1 2017-09-13 11:12:25

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

my mORMot MVC web application journey

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

#2 2017-09-13 12:02:56

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,225
Website

Re: my mORMot MVC web application journey

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

#3 2017-09-16 21:29:58

wai-kit
Member
From: Amsterdam, the Netherlands
Registered: 2012-11-27
Posts: 90

Re: my mORMot MVC web application journey

Merci, Arnaud.


fpcdeluxe, FPC 3.2 / Lazarus 2.0, mORMot on Windows 10 ...

Offline

Board footer

Powered by FluxBB