webmcp

diff framework/env/request/redirect.lua @ 0:9fdfb27f8e67

Version 1.0.0
author jbe/bsw
date Sun Oct 25 12:00:00 2009 +0100 (2009-10-25)
parents
children ca88032cb37c
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/framework/env/request/redirect.lua	Sun Oct 25 12:00:00 2009 +0100
     1.3 @@ -0,0 +1,39 @@
     1.4 +--[[--
     1.5 +request.redirect{
     1.6 +  module = module,  -- module name
     1.7 +  view   = view,    -- view name
     1.8 +  id     = id,      -- optional id for view
     1.9 +  params = params   -- optional view parameters
    1.10 +}
    1.11 +
    1.12 +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.
    1.13 +
    1.14 +--]]--
    1.15 +
    1.16 +function request.redirect(args)
    1.17 +  -- TODO: support redirects to external URLs too
    1.18 +  --       (needs fixes in the trace system as well)
    1.19 +  local module = args.module
    1.20 +  local view   = args.view
    1.21 +  local id     = args.id
    1.22 +  local params = args.params or {}
    1.23 +  if type(module) ~= "string" then
    1.24 +    error("No module string passed to request.redirect{...}.")
    1.25 +  end
    1.26 +  if type(view) ~= "string" then
    1.27 +    error("No view string passed to request.redirect{...}.")
    1.28 +  end
    1.29 +  if type(params) ~= "table" then
    1.30 +    error("Params array passed to request.redirect{...} is not a table.")
    1.31 +  end
    1.32 +  if request.is_rerouted() then
    1.33 +    error("Tried to redirect after another forward or redirect.")
    1.34 +  end
    1.35 +  request._redirect = {
    1.36 +    module = module,
    1.37 +    view   = view,
    1.38 +    id     = id,
    1.39 +    params = params
    1.40 +  }
    1.41 +  trace.redirect{ module = args.module, view = args.view }
    1.42 +end

Impressum / About Us