webmcp
diff framework/env/request/get_param.lua @ 214:6ac7133bb58e
Work on Moonbridge integration: added execute._initializers(...), new function request.get_param{...}; Code cleanup in mcp.lua and tempstore.save(...)
author | jbe |
---|---|
date | Sat Jan 10 10:44:17 2015 +0100 (2015-01-10) |
parents | |
children | 264af2867720 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/request/get_param.lua Sat Jan 10 10:44:17 2015 +0100 1.3 @@ -0,0 +1,33 @@ 1.4 +--[[-- 1.5 +value = -- value of GET/POST parameter, or value list if multiple == true 1.6 +request.get_param{ 1.7 + method = method, -- "GET", "POST", or nil to query both (POST has precedence) 1.8 + name = name, -- field name 1.9 + index = index, -- defaults to 1 to get first occurrence, only applicable if multiple == false 1.10 + multiple = multiple -- boolean to indicate whether to return a single value or a value list 1.11 +} 1.12 + 1.13 +Reads GET/POST parameters directly from the underlaying request. 1.14 + 1.15 +--]]-- 1.16 + 1.17 +function request.get_param(args) 1.18 + local param_list 1.19 + if args.method == "GET" then 1.20 + param_list = request._http_request.get_params_list[args.name] 1.21 + elseif args.method == "POST" then 1.22 + param_list = request._http_request.post_params_list[args.name] 1.23 + elseif not args.method then 1.24 + param_list = request._http_request.post_params_list[args.name] 1.25 + if not param_list[index or 1] then 1.26 + param_list = request._http_request.get_params_list[args.name] 1.27 + end 1.28 + end 1.29 + if multiple then 1.30 + return param_list 1.31 + else 1.32 + return param_list[index or 1] 1.33 + end 1.34 +end 1.35 + 1.36 +--//--