#1 2014-10-15 04:40:21

yudipe
Member
Registered: 2014-10-15
Posts: 3

Need simple MVC web app using synmustache sample project...

Hello ... Good morning mORMot community..

yesterday , i just downloaded mormot nightly build + sqlite3*.obj
after reading readme.txt, i then compile and running testsqlite3.dpr / testsqlite3register.dpr successfully.
i'm currently using delphi xe6 on windows7 32 bit

i then look at sample folders and really sad because there is no simple demo explaining how to build mvc web application using mormot.

Let's take simple blog app with simple CRUD and authentication as example.
The app will be running on localhost on port 80. I need the following example :

1. How to define model (article and user) using TSqlRecord
2. How to define controller / router class, for example :
    Public route (no need authetication / anonymous user can access)
    - localhost ==> will show main page with list of all articles
    - localhost/article/1 ==> will show article with id = 1
    Protected route (user must login before coming into this page)
    - localhost/article/1/edit ==> will show editing page for article id = 1, then posting data back via html form
    - localhost/article/new ==> will show page to create new article
    - localhost/article/1/delete ==> to delete the article
3. How to define Layout/View using SynMustache to display above page (point no. 2)
4. At this time i don't need javascript / json. Just html generated on the server side
5. Deployment on server

Okay, thats all.
Hope other newbies with the same problem can take advantage from the demo

Thanks
Yudi Purwanto

Offline

#2 2014-10-15 05:05:10

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

Re: Need simple MVC web app using synmustache sample project...

By default, the routing will return the content as JSON, with a "root" name tied to the model.
It is a true RESTful routing.
So localhost/root would be the "root" for the TSQLModel with root='root'.
Then localhost/root/article will will let GET return the list of people IDs, as JSON, and PUT create a new TSQLArticle resource.
Then localhost/root/article/1 will handle the GET/POST/DELETE REST commands on the article record with ID=1, as JSON.
See the doc about it.
All this is automatic, without any configuration needed.

But classic HTML MVC is not directly available, but easily feasible, with method-based services.
I will try to write some simple demo.

Offline

#3 2014-10-15 05:31:42

yudipe
Member
Registered: 2014-10-15
Posts: 3

Re: Need simple MVC web app using synmustache sample project...

Thank you for your quick respons Mr. AB

I just found 2 years old project on Github created by an Indian programmer
link : https://github.com/gkathire/DelphiMVC/t … vcWEB/Blog

it seems, the project creator is aimed to mimic the ASP.NET MVC behaviour, from the short description ...

the server side also using mormot & sqlite3 (i guess it is mormot version 1.17)
but the view using Delphi Web Srcipt (DWS)
and sorry ... the model using own ORM that i saw more elegant than TSQLRecord :-)

Actually i'm novice in Delphi for internet/server programming.
I try to compile the sample project using XE6, but Delphi stop and showing error at some point (superobject.pas) ...undeclared variable...bla..bla...

Maybe you can take this project as sample


Thanks
Yudi Purwanto

Offline

#4 2014-10-15 06:28:57

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

Re: Need simple MVC web app using synmustache sample project...

I did know this project!
This is a great piece of code.
Attribute-driven ORM of PODO (Plain Old Delphi Object) sounds "sexy", but in fact, it needs to write some wrappers since the parent TSQLRecord is a very convenient way (thanks to the powerful Delphi "class of" type definition) to rely on abstractions (following the Liskov principle).
Of course, our mORMot framework has so much more features, and much better performance (the SQL generation is very basic, and unsafe, due to potential SQL injection issues)...
This framework is IMHO better than Brooks, with a similar goal.

Let's see what we can do with mORMot, in terms of MVC applications.
Perhaps it is time to start implementing http://synopse.info/fossil/tktview?name=bd94c11ab1
Do you have some simple reference MVC sample to start with, with some data and views?

Offline

#5 2014-10-15 07:13:06

yudipe
Member
Registered: 2014-10-15
Posts: 3

Re: Need simple MVC web app using synmustache sample project...

Okay .. Mr. AB

I have a little experience in .NET and PHP, so i will take them as reference

from the .NET world (using nancy framework ==> sinatra for .NET)
article and demo : http://people-1.apphb.com/
source code : https://bitbucket.org/woodwardmatt/people

from PHP world (using slim framework ==>sinatra for PHP)
1. https://github.com/chrisgillis/Slim-Blog

2. or using Fat-Free framework. link : http://www.willis-owen.co.uk/2013/02/bl … mework-v3/

Okay, show me to achieve this kind of App using mORMot Mr.AB

Thanks..

Offline

#6 2014-10-15 16:58:52

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

Re: Need simple MVC web app using synmustache sample project...

I'm working on it.

In fact, I'm implementing the whole MVC feature request.

Draft version of the corresponding documentation is the following:

This basic MVC design has been enhanced, and benefit from interface-based services - see Client-Server services via interfaces - to define a true MVVM model via mORMotMVC.pas:

MVVM   mORMot
   Model   Object-Relational Mapping (ORM) and its TSQLModel / TSQLRecord definitions
   View   Mustache template engine
(may be stored as separated files or within the database)
   ViewModel   Interface-based services - see Client-Server services via interfaces

In the MVVM pattern, both Model and View components do match the classic Model-View-Controller layout. But the ViewModel will define some kind of "model for the view", i.e. the data context to be sent and retrieved from the view.

In the mORMot implemenation, interface-based services methods are used to define the execution context of any request, following the convention over configuration pattern of our framework.
In fact, the following conventions are used to define the ViewModel:

ViewModel   mORMot
   Route   From the interface name and its method name
   Command   Defined by the method name
   Controller   Defined by the method implementation
   Input Context   Transmitted as method input parameters (const/var) from the View
   Output Context   Method output parameters (var/out) are sent to the View
   Actions   By default, a procedure method will render the associated view with the output parameters, but you can define a function and (optionally) redirect to any other action/uri

This may sounds pretty unusual (if you are coming from a RubyOnRails, AngularJS, Meteor or .Net implementations), but it has been identified to be pretty convenient to use, since you do not need to define explicit data structures for the ViewModel layer. For instance, this implementation uses the interface input and output parameters are an alternate way to define the $scope content of an AngularJS application.

Offline

#7 2014-10-17 16:21:58

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

Re: Need simple MVC web app using synmustache sample project...

Take a look at http://synopse.info/fossil/info/fae587bc9de21551260438

Not finished yet, but seems quite a good start!

Any feedback is welcome, or help for writing the Views Mustache files.
We would like to use bootstrap, perhaps starting from http://getbootstrap.com/examples/blog

Offline

#8 2015-03-11 13:55:36

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Need simple MVC web app using synmustache sample project...

IMHO http://semantic-ui.com/  as two advantages over bootstrap:

- It's syntax is sematic!
- It's built-in themes (several of them) are much good-looking .


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

#9 2015-03-12 09:01:38

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

Re: Need simple MVC web app using synmustache sample project...

Could you help us to update the Mustache views of the sample so that it would use it instead of bootstrap?

Offline

#10 2015-03-12 10:17:24

edwinsn
Member
Registered: 2010-07-02
Posts: 1,218

Re: Need simple MVC web app using synmustache sample project...

Hi Arnaud,

I'm at the stage of evaluating using the MVVM mechanism provided by mORMot, if I go ahead, I'd rather spend time on more useful things, like making mORMotMVC.pas to have an option of always loading files from disk, so that one can tweak and test the html/css/js in realtime without having to restart the program.

It's an example, using bootstrap or other css framework is not important for the purpose of demonstration.


Delphi XE4 Pro on Windows 7 64bit.
Lazarus trunk built with fpcupdelux on Windows with cross-compile for Linux 64bit.

Offline

Board footer

Powered by FluxBB