rgb192
asked on
header get variables (object oriented)
I have this in a header file which I include in every file, because I use get variables in mysql queries
also I add new variables
so I am looking for an object oriented solution
I dont fully understand this modified code sample and how to add new get header variables
also I add new variables
$id=mysqli_real_escape_string ($dbc, $_GET['id']);
$key=mysqli_real_escape_string($dbc, $_GET['key']);
$level=mysqli_real_escape_string ($dbc, $_GET['level']);
$sort =mysqli_real_escape_string ($dbc,$_GET['sort']);
$response=mysqli_real_escape_string ($dbc,$_GET['response']);
$tablename=mysqli_real_escape_string ($dbc,$_GET['tablename']);
$getinsert=mysqli_real_escape_string ($dbc,$_GET['insert']);
$gettablenameid=mysqli_real_escape_string($dbc,$_GET[$tablename.'_id']);
$getemailtemplateid=mysqli_real_escape_string($dbc,$_GET['email_template_id']);
so I am looking for an object oriented solution
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
// DEMONSTRATE AN OBJECT-ORIENTED APPROACH TO HANDLING GET-METHOD REQUEST VARIABLES
Class GetVars
{
// OUR CLASS VARS MATCH $_GET KEYS
public $u = NULL, $q = NULL;
// THIS IS AN EXCEPTION TRIGGER, PERHAPS?
public $err = 'Missing Data';
public function __construct()
{
// THIS IS WHERE WE WILL FILTER THE $_GET DATA
$this->u = !empty($_GET['u']) ? $_GET['u'] : NULL;
$this->q = !empty($_GET['q']) ? $_GET['q'] : NULL;
$this->id=!empty($_GET['id']) ? $_GET['id'] : NULL;
$this->key=!empty($_GET['key']) ? $_GET['key'] : NULL;
$this->level=!empty($_GET['level']) ? $_GET['level'] : NULL;
$this->sort =!empty($_GET['sort']) ? $_GET['sort'] : NULL;
$this->response=!empty($_GET['response']) ? $_GET['response'] : NULL;
$this->tablename=!empty($_GET['tablename']) ? $_GET['tablename'] : NULL;
$this->getinsert=!empty($_GET['getinsert']) ? $_GET['getinsert'] : NULL;
$this->gettablenameid=!empty($_GET['gettablenameid']) ? $_GET['gettablenameid'] : NULL;
$this->getemailtemplateid=!empty($_GET['getemailtemplateid']) ? $_GET['getemailtemplateid'] : NULL;
// THIS IS WHERE WE WILL TEST FOR ACCEPTABLE COMBINATIONS IN THE REQUEST
if ($this->u && $this->q) $this->err = NULL;
}
}
// INSTANTIATE THE CLASS
$reqdata = new Getvars();
// TEST FOR ACCEPTABLE DATA
if ($reqdata->err) echo "SOMETHING IS WRONG: $reqdata->err";
// IF THERE ARE NO ERRORS, USE THE EXTERNAL DATA
if (!$reqdata->err)
{
echo "THE 'u' VALUE IS: $reqdata->u";
echo "<br>";
echo "THE 'q' VALUE IS: $reqdata->q";
}
I dont fully understand this modified code sample and how to add new get header variables
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
these code samples offer insight and explanation
thanks
thanks
http://www.amazon.com/Objects-Patterns-Practice-Experts-Source/dp/143022925X/
Or follow this search:
https://www.google.com/search?q=PHP+object-oriented+design