2016-09-06 10:30:52 +02:00
|
|
|
unit MyControllerU;
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2017-01-18 21:53:53 +01:00
|
|
|
MVCFramework, MVCFramework.Commons;
|
2016-09-06 10:30:52 +02:00
|
|
|
|
|
|
|
type
|
|
|
|
|
2023-06-05 10:01:09 +02:00
|
|
|
[MVCPath]
|
2016-09-06 10:30:52 +02:00
|
|
|
TMyController = class(TMVCController)
|
|
|
|
public
|
2023-06-05 10:01:09 +02:00
|
|
|
[MVCPath]
|
2016-09-06 10:30:52 +02:00
|
|
|
[MVCHTTPMethod([httpGET])]
|
|
|
|
procedure Index;
|
|
|
|
|
|
|
|
[MVCPath('/hellos/($FirstName)')]
|
|
|
|
[MVCHTTPMethod([httpGET])]
|
|
|
|
procedure GetSpecializedHello(const FirstName: string);
|
|
|
|
procedure OnBeforeAction(Context: TWebContext; const AActionName: string;
|
|
|
|
var Handled: Boolean); override;
|
|
|
|
procedure OnAfterAction(Context: TWebContext; const AActionName: string); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
|
|
|
|
procedure TMyController.Index;
|
|
|
|
begin
|
|
|
|
// use Context property to access to the HTTP request and response
|
|
|
|
ContentType := TMVCMediaType.TEXT_PLAIN;
|
|
|
|
ResponseStream
|
|
|
|
.AppendLine('WARNING!')
|
|
|
|
.AppendLine
|
|
|
|
('Run this program in debug and check the Delphi "Event" debug window to see the custom logs')
|
2017-01-18 21:53:53 +01:00
|
|
|
.AppendLine('Also, the log file are generated in the custom path "MyFolder\MyLogs"');
|
2016-11-18 00:17:18 +01:00
|
|
|
RenderResponseStream;
|
2016-09-06 10:30:52 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyController.GetSpecializedHello(const FirstName: string);
|
|
|
|
begin
|
|
|
|
Render('Hello ' + FirstName);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyController.OnAfterAction(Context: TWebContext; const AActionName: string);
|
|
|
|
begin
|
|
|
|
{ Executed after each action }
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TMyController.OnBeforeAction(Context: TWebContext; const AActionName: string;
|
|
|
|
var Handled: Boolean);
|
|
|
|
begin
|
|
|
|
{ Executed before each action
|
|
|
|
if handled is true (or an exception is raised) the actual
|
|
|
|
action will not be called }
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|