Ver Mensaje Individual
  #3 (permalink)  
Antiguo 21/01/2006, 20:27
Avatar de kalolo
kalolo
 
Fecha de Ingreso: abril-2005
Mensajes: 65
Antigüedad: 19 años, 1 mes
Puntos: 0
index.php
Código PHP:
/*- Probando Objetos -*/
/*EL objeto es llenado por la info en los textbox, y almacenado tantas veces le des enviar datos, e impreso al dar ejecutar */ 
session_start(); 
echo
'<link href="estilo.css" rel="stylesheet" type="text/css">';
require 
"funciones.php";
require 
"class.php";
require 
"dBug/dBug.php";
echo
'<title>: Probando Objetos :</title>';
pon_tabla();
@
$op=$_GET['op'];
@
$file=$_GET['archivo'];
if(
$op=="source")
{
    if(
$file=="class")
     
highlight_file("class.php");
    else
     
highlight_file("index.php");        
}
else
{
    if(isset(
$_POST['enviar']))
    {
        if(isset(
$_SESSION['cont']))
        {        
         
$_SESSION['cont']++;
         
$Objeto=new Usuario($_POST['nombre'], $_POST['edad'], $_POST['sexo'], $_POST['domicilio'], $_POST['telefono'], $_POST['salario'], $_POST['rfc']);         
         
$_SESSION['Objetos'][]=serialize($Objeto);//<-- "empaquetamos el objeto
          
echo '<span class="txt2">Usuarios agregados: '.$_SESSION['cont'].'</span>';
         
// serialize a como veo, lo que hace es enpaqutarlo, y agarrar todo el objeto y conevertirlo a .. variable :| 
        
}
        else
        {
         
$_SESSION['cont']=1;
         
$_SESSION['Objetos']=array();         
        
$Objeto=new Usuario($_POST['nombre'], $_POST['edad'], $_POST['sexo'], $_POST['domicilio'], $_POST['telefono'], $_POST['salario'], $_POST['rfc']);
         
$_SESSION['Objetos'][]=serialize($Objeto);//<-- Te laaaaa pelas mendigo objeto!!!
         
echo '<span class="txt2">Usuarios agregados: '.$_SESSION['cont'].'</span>';
         }            
    }
        
/* Imprimos los objetos */
        
if(isset($_POST['ejecutar']))
        {    
           echo 
'<span class="txt2">Total de usuarios agregados: '.$_SESSION['cont'].'</span><br>';
           echo 
'<span class="txt2">: Debug: Session con los objetos aun serialisados :</span>';
           new 
dBug($_SESSION['Objetos']);echo"<br>"
           
            echo 
'<span class="txt2">: Debug: Objetos des-serialisados :</span><br>';
            foreach(
$_SESSION['Objetos'] as $Objeto)    
            {                    
               
$Obj=unserialize($Objeto);//<- :) desempaquetamos 
                
                     
echo '<br><span class="txt2">'.$Obj.'</span><br>';
                        foreach(
$Obj->Campos as $Campos)
                          echo 
'<span class="txt2">'.$Campos.': </span><span class="txt1">'.$Obj->$Campos.'</span><br>';
                echo
"<br>";new dBug($Obj); 
            }
        }

class.php
Código PHP:
class Usuario {
  
   public 
$Nombre;
   public 
$Edad;
   public 
$Sexo;
   public 
$Domicilio;
   public 
$Telefono;
   public 
$Salario;
   public 
$RFC;
  
   public function 
__construct($Nombre,$Edad,$Sexo,$Domicilio,$Telefono,$Salario,$RFC
   {
        
$this->Nombre $Nombre;
        
$this->Edad $Edad;
        
$this->Sexo $Sexo;
        
$this->Domicilio $Domicilio;
        
$this->Telefono $Telefono;
        
$this->Salario $Salario;
        
$this->RFC $RFC;
        
$this->Campos = array("Nombre""Edad""Sexo""Domicilio""Telefono""Salario""RFC");
        
   }
  
   public function 
__destruct() {

   }
   public function 
imprime()
   {
    echo 
$this->Nombre;
    echo 
$this->Nombre;
    echo 
$this->Edad;
    echo 
$this->Sexo;
    echo 
$this->Domicilio;
    echo 
$this->Telefono;
    echo 
$this->Salario;
    echo 
$this->RFC;
   }


funciones.php
Código PHP:
function pon_tabla()
{
    echo
'<table width="650" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><form name="form1" method="post" action="index.php">
      <table width="100%"  border="0" cellspacing="2" cellpadding="0">
        <tr>
          <td class="title1"><a href="?op=source" class="title1-link">[ver source] </a></td>
          <td class="title1"><a href="?op=source&archivo=class" class="title1-link">[codigo fuente de la class]</a></td>
        </tr>
        <tr>
          <td width="15%" class="title1">Nombre:</td>
          <td width="85%"><input name="nombre" type="text" class="estilo-inputs1" id="nombre" size="50"></td>
        </tr>
        <tr>
          <td class="title1">Edad</td>
          <td><input name="edad" type="text" class="estilo-inputs1" id="edad" size="50"></td>
        </tr>
        <tr>
          <td class="title1">Sexo</td>
          <td><input name="sexo" type="text" class="estilo-inputs1" id="sexo" size="50"></td>
        </tr>
        <tr>
          <td class="title1">Domicilio</td>
          <td><input name="domicilio" type="text" class="estilo-inputs1" id="domicilio" size="50"></td>
        </tr>
        <tr>
          <td class="title1">Telefono</td>
          <td><input name="telefono" type="text" class="estilo-inputs1" id="telefono" size="50"></td>
        </tr>
        <tr>
          <td class="title1">Salario</td>
          <td><input name="salario" type="text" class="estilo-inputs1" id="salario" size="50"></td>
        </tr>
        <tr>
          <td class="title1">RFC</td>
          <td><input name="rfc" type="text" class="estilo-inputs1" id="rfc" size="50"></td>
        </tr>
        <tr>
          <td><input name="enviar" type="submit" class="Boton2" id="enviar" value="    Guardar    "></td>
          <td><input name="ejecutar" type="submit" class="Boton2" id="ejecutar" value=" Imprimir datos "></td>
        </tr>
      </table>
    </form></td>
  </tr>
</table>'
;


__________________
There is no place like 127.0.0.1