NOTE: I will be updating this periodically to make it better. I am going to expand on it and make it a post and get class. The current version is 1.0
Here is a flexible GETTER class if anyone is interested. I am always open to improving it. Its pretty simple. Suggestions welcome.
Getter.php
PHP Code:
<?php
/*
Author: Chris Hickingbottom
Date: 3/16/2012
Description: This class is designed to flexibly grab the variables in a url.
Version: 1.0
*/
class Getter {
private $getters = array();
function __construct($gets) {
foreach ($gets as $get=>$default) {
$value = !empty($_GET[$get]) ? $_GET[$get] : $default;
$this->getters[$get] = $value;
}
}
public function getGetter($get) {
return $this->getters[$get];
}
}
Example.php
PHP Code:
<?php
require_once('getter.php'); // include the file.
// set the variables you are searching for in an array
// the key being the name of the variable and the other being the default value if it is not set
$gets = array('firstName'=>false, 'lastName'=>false);
$getter = new Getter($gets); // initialize the class using the array of variables that you want
$carType=$getter->getGetter('carType'); // grab the specific infomation you want
$carModel=$getter->getGetter('carModel'); // grab the specific information you want
if(!$carType) {
echo 'False';
} else {
echo $carType;
}
echo "<br />";
if(!$carModel) {
echo 'False';
} else {
echo $carModel;
}
?>