webmcp

view framework/env/request/redirect.lua @ 401:ad437022be90

Quick fix to avoid problems on document creation
author jbe
date Mon Jan 04 00:48:47 2016 +0100 (2016-01-04)
parents bac6cbdeb055
children 4e03ecb28665
line source
1 --[[--
2 request.redirect{
3 external = external, -- external URL (instead of specifying base, module, etc. below)
4 base = base, -- optional string containing a base URL of a WebMCP application
5 static = static, -- an URL relative to the static file directory
6 module = module, -- a module name of the WebMCP application
7 view = view, -- a view name of the WebMCP application
8 action = action, -- an action name of the WebMCP application
9 id = id, -- optional id to be passed to the view or action to select a particular data record
10 params = params, -- optional parameters to be passed to the view or action
11 anchor = anchor -- anchor in URL
12 }
14 Calling this function causes the WebMCP to do a 303 HTTP redirect after the current view or action and all filters have finished execution. If routing mode "redirect" has been chosen, then this function is called automatically after an action and all its filters have finished execution. Calling request.redirect{...} (or request.forward{...}) explicitly inside an action will cause routing information from the browser to be ignored. To preserve GET/POST parameters of an action, use request.forward{...} instead. Currently no redirects to external (absolute) URLs are possible, there will be an implementation in future though.
16 --]]--
18 function request.redirect(args)
19 args = table.new(args)
20 if type(args.external) ~= "string" and type(args.static) ~= "string" then
21 if type(args.module) ~= "string" then
22 error("No module string passed to request.redirect{...}.")
23 end
24 if type(args.view) ~= "string" then
25 error("No view string passed to request.redirect{...}.")
26 end
27 if args.params ~= nil and type(args.params) ~= "table" then
28 error("Params array passed to request.redirect{...} is not a table.")
29 end
30 if args.anchor ~= nil and type(args.anchor) ~= "string" then
31 error("Anchor passed to request.redirect{...} must be a string or nil.")
32 end
33 end
34 if request.is_rerouted() then
35 error("Tried to redirect after another forward or redirect.")
36 end
37 request._redirect = args
38 if args.module and args.view then -- TODO: support for external redirects
39 trace.redirect{ module = args.module, view = args.view }
40 end
41 end

Impressum / About Us