webmcp
view framework/env/param/get.lua @ 1:985024b16520
Version 1.0.1
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
New feature: JSON requests
Changes in ui.paginate: Current page setting is directly fetched from CGI params, instead of view params
Changed behavior of load methods of atom library to accept nil as input
Bugfixes in mondelefant_atom_connector timestamp(tz) loaders
Added global constant _WEBMCP_VERSION containing a version string
| author | jbe | 
|---|---|
| date | Tue Nov 17 12:00:00 2009 +0100 (2009-11-17) | 
| parents | 9fdfb27f8e67 | 
| children | 32ec28229bb5 | 
 line source
     1 --[[--
     2 value =       -- value of the parameter casted to the chosen param_type
     3 param.get(
     4   key,        -- name of the parameter
     5   param_type  -- desired type of the returned value
     6 )
     8 Either a GET or POST request parameter is returned by this function, or if param.exchange(...) was called before, one of the exchanged parameters is returned. You can specify which type the returned value shall have. If an external request parameter was used and there is another GET or POST parameter with the same name but a "__format" suffix, the parser with the name of the specified format will be automatically used to parse and convert the input value.
    10 --]]--
    12 function param.get(key, param_type)
    13   local param_type = param_type or atom.string
    14   if param._exchanged then
    15     local value = param._exchanged.params[key]
    16     if value ~= nil and not atom.has_type(value, param_type) then
    17       error("Parameter has unexpected type.")
    18     end
    19     return value
    20   else
    21     local str         = cgi.params[key]
    22     local format_info = cgi.params[key .. "__format"]
    23     if not str then
    24       if not format_info then
    25         return nil
    26       end
    27       str = ""
    28     end
    29     return param._get_parser(format_info, param_type)(str)
    30   end
    31 end
