note 44902 added to function.import-request-variables
| From: | davidb at mnl dot com | Date: | Thu, 19 Aug 2004 18:58:24 +0000 |
| Subject: | note 44902 added to function.import-request-variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-74943@lists.php.net to get a copy of this message | ||
I missed the parameterized requests from HTML::Mason in perl, so hacked up my own equivalent; then
basically at the top of pretty much every page i just say:
args('blah?', 'username', '=password');
something like that. The docs are in the comments at the top:
## assigns various REQUEST vars to global vars
## arguments are a variable number of strings, each of which will be turned
## into a global variable (e.g. 'foo' => $foo (or $GLOBALS['foo']))
## arguments are assumed to be required to exist, unless they are followed
## by a ? (e.g. 'foo?' is 'foo' optionally (still 'foo' => $foo))
## if the argument is preceeded with an = (e.g. '=foo' or '=foo?'), then
## it will not be trim()'ed before the variable is set
##
## you may also pass all of the arguments as a single array
function args() {
$keys = func_get_args();
if (count($keys) == 1 && is_array($keys[0])) $keys = $keys[0];
foreach ($keys as $key) {
if (substr($key, 0, 1) == '=') {
$key = substr($key, 1);
$trim = false;
} else $trim = true;
if (substr($key, -1) == '?') {
$key = substr($key, 0, strlen($key) - 1);
$GLOBALS[$key] = (array_key_exists($key, $_REQUEST))
? $_REQUEST[$key] : NULL;
} else {
if (!array_key_exists($key, $_REQUEST))
die("Missing required argument for this page: '$key'");
$GLOBALS[$key] = $_REQUEST[$key];
}
if ($trim && !is_array($GLOBALS[$key]) && !is_null($GLOBALS[$key]))
$GLOBALS[$key] = trim($GLOBALS[$key]);
}
}
----
Manual Page -- http://www.php.net/manual/en/function.import-request-variables.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+44902
Delete -- http://master.php.net/manage/user-notes.php?action=delete+44902&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+44902&report=yes
Search -- http://master.php.net/manage/user-notes.php