webmcp
diff framework/env/param/get_id.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children | 2f8d8edd1836 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/param/get_id.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,22 @@ 1.4 +--[[-- 1.5 +value = -- value of the id casted to the chosen param_type 1.6 +param.get_id( 1.7 + param_type -- desired type of the returned value 1.8 +) 1.9 + 1.10 +Same as param.get(...), but operates on a special id parameter. An id is set via a __webmcp_id GET or POST parameter or an 'id' option to execute.view{...} or execute.action{...}. In a normal setup a beauty URL of the form http://www.example.com/example-application/example-module/example-view/<id>.html will cause the id to be set. 1.11 + 1.12 +--]]-- 1.13 + 1.14 +function param.get_id(param_type) 1.15 + local param_type = param_type or atom.integer 1.16 + if param._exchanged then 1.17 + local value = param._exchanged.id 1.18 + if value ~= nil and not atom.has_type(value, param_type) then 1.19 + error("Parameter has unexpected type.") 1.20 + end 1.21 + return value 1.22 + else 1.23 + return param.get("_webmcp_id", param_type) 1.24 + end 1.25 +end