Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/01/2006, 14:53
Avatar de biblio
biblio
 
Fecha de Ingreso: enero-2002
Ubicación: Urano
Mensajes: 577
Antigüedad: 22 años, 4 meses
Puntos: 0
Obtener datos de $_POST, $_GET, etc. [Ejemplo]

La necesidad mia de querer obtener datos de las Variables Predefinidas $_POST, $_GET, $_REQUEST, $_SESSION, $_SERVER, etc. Llegué a esto, espero les sirva a uds.

Espero sus comentarios y contribución a la mejora.

Además debo decirles que estoy volviendo por estos lares luego de mucho tiempo.

Código PHP:
<?php
class Variables
{
    private 
$key;
    private 
$value;
    
    public function 
__construct($vars) {
        
$this->key   $vars['key'];
        
$this->value $vars['value'];
    }

    public function 
Key() {
        return 
$this->key;
    }
    
    public function 
Value() {
        return 
$this->value;
    }        
}



abstract class 
_factory //factorizacion
    
    
private $index 0;
    
    public function 
getVariables() {
        if(isset(
$this->vars[$this->index])) {
            return new 
Variables($this->vars[$this->index++]);
        } else {
            
$this->index 0;
            return 
false;
        }
    }
}

class 
PredefinedVariables extends _factory {
    
    protected 
$vars = array();

    public function 
__construct($prefvars
    {        
        foreach(
$prefvars as $key => $value) {
            
$this->vars[] = array('key'=>$key,'value'=>$value);
        }
    }    
}

if (!isset(
$_SESSION['biblio']))
{
    
$_SESSION['biblio'] = 'BIBLIO';
}

//$n = new PredefinedVariables($_SESSION);

$n = new PredefinedVariables($_POST); // puede probar tambien con $_GET, $_SERVER, $_REQUEST, $_SESSION, etc.

print '<pre>';
while( 
$kv $n->getVariables() ) {
    echo 
'<strong>'.$kv->Key().'</strong>';
    echo 
'<br>'.$kv->Value().'<br>';
}
?>
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style></head>

<body>
<form action="" method="post" enctype="multipart/form-data" name="form1">
  <table width="100%" border="0">
    <tr>
      <td width="13%">TextBox</td>
      <td width="87%"><input name="textfield" type="text" value="text"></td>
    </tr>
    <tr>
      <td>ComboBox</td>
      <td><select name="select">
        <option selected>Option</option>
        <option>a</option>
        <option>b</option>
        <option>c</option>
      </select></td>
    </tr>
    <tr>
      <td>Button</td>
      <td><input type="submit" name="Submit" value="Send"></td>
    </tr>
  </table>
</form>
</body>
</html>
Solo debes hacer lo siguiente para probar:

Copiar, pegar en un archivo x.php, ejecutar en tu localhost o cual sea y dar clic en el boton del formulario.
Saludos

Última edición por Cluster; 07/01/2006 a las 14:55