Sneak peek to simple integration between DMVCFramework and DORM
· 1 min read
This is a really simple (not optimized and dirty) integration between the upcoming DMVCFramework (WebBroker based MVC framework) and DORM, “the Delphi ORM”.
[This is the DMVCFramework controller with the relative mapping and methods. In the method “GetUsers” dorm is used to execute a select to the database using the sanitized parameter passed on the url.]{style=“font-size: 13px;”}
unit UsersControllerU;
interface
uses MVCFramework, dorm;
type
[MVCPath('/users')]
TUsersController = class(TMVCController)
strict private
dormSession: TSession;
strict protected
procedure MVCControllerAfterCreate; override;
procedure MVCControllerBeforeDestroy; override;
public
[MVCPath('/($id)')]
[MVCHTTPMethod([httpGET])]
procedure GetUsers(CTX: TWebContext);
end;
implementation
uses
dorm.loggers, dorm.adapters, dorm.Commons, UsersBO;
{ TUsersController }
procedure TUsersController.GetUsers(CTX: TWebContext);
var
User: TUser;
begin
User := dormSession.Load < TUser > (CTX.Request.ParamsAsInteger['id']);
Render(User);
end;
procedure TUsersController.MVCControllerAfterCreate;
begin
inherited;
dormSession := TSession.CreateConfigured('dorm.conf', TdormEnvironment.deDevelopment);
end;
procedure TUsersController.MVCControllerBeforeDestroy;
begin
dormSession.Free;
inherited;
end;
end.
Now, if you run the application and go to http://localhost/users/1 (the server is running on port 80), you’ll get the following:
Stay tuned.
Comments
comments powered by Disqus