mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-16 00:05:53 +01:00
56 lines
1.3 KiB
ObjectPascal
56 lines
1.3 KiB
ObjectPascal
|
unit SampleControllerU;
|
||
|
|
||
|
interface
|
||
|
|
||
|
uses
|
||
|
MVCFramework, MVCFramework.Commons;
|
||
|
|
||
|
type
|
||
|
|
||
|
[MVCPath('/')]
|
||
|
TSampleController = class(TMVCController)
|
||
|
public
|
||
|
[MVCHTTPMethod([httpGet])]
|
||
|
[MVCPath('/($searchtext)/($page)')]
|
||
|
[MVCProduce('text/plain')]
|
||
|
procedure SearchCustomers(CTX: TWebContext);
|
||
|
|
||
|
[MVCHTTPMethod([httpPost])]
|
||
|
[MVCPath('/customers')]
|
||
|
[MVCProduce('text/plain')]
|
||
|
[MVCConsumes('text/*')]
|
||
|
procedure CreateCustomer(CTX: TWebContext);
|
||
|
|
||
|
end;
|
||
|
|
||
|
implementation
|
||
|
|
||
|
uses
|
||
|
System.SysUtils;
|
||
|
|
||
|
{ TRoutingSampleController }
|
||
|
|
||
|
procedure TSampleController.CreateCustomer(CTX: TWebContext);
|
||
|
begin
|
||
|
ResponseStream.Append('First name: ' + CTX.Request.Params['first_name'] +
|
||
|
sLineBreak + 'Last name: ' + CTX.Request.Params['last_name']);
|
||
|
Render;
|
||
|
end;
|
||
|
|
||
|
procedure TSampleController.SearchCustomers(CTX: TWebContext);
|
||
|
var
|
||
|
search: string;
|
||
|
p: Integer;
|
||
|
orderby: string;
|
||
|
begin
|
||
|
search := CTX.Request.Params['searchtext'];
|
||
|
p := CTX.Request.ParamsAsInteger['page'];
|
||
|
orderby := '';
|
||
|
if CTX.Request.QueryStringParamExists('order') then
|
||
|
orderby := CTX.Request.QueryStringParam('order');
|
||
|
Render(Format('SEARCHTEXT: "%s", PAGE: %d, ORDERBYFIELD: "%s"',
|
||
|
[search, p, orderby]));
|
||
|
end;
|
||
|
|
||
|
end.
|