Ver Mensaje Individual
  #7 (permalink)  
Antiguo 01/10/2008, 07:23
vvillar21
 
Fecha de Ingreso: mayo-2007
Ubicación: Los Teques -Edo Miranda
Mensajes: 43
Antigüedad: 17 años
Puntos: 0
Respuesta: Duda con Clases

Hola muchas gracias a todos por sus respuestas, efectivamente lo mejor es crear otra instancia de la clase fecha lo probe y me funciono como quería. Lo que realmente tengo es una clase fecha donde están los getters y setters de los campos dia, mes y anio


Código:
Código PHP:
//ARCHIVO fecha.php
<?php
       
class Fechas{
           private 
$vFecha;
       private 
$vHora;
       private 
$vDia;
       private 
$vMes;
       private 
$vAnio;

    
//CONSTRUCTOR
    
public function __construct(){
        
$this->vFecha $this->SetFecha("00/00/0000");
        
$this->vHora $this->SetHora("00:00");
        
$this->vDia $this->SetDia("00");
        
$this->vMes $this->SetMes("00");
        
$this->vAnio $this->SetAnio("0000");
    }

    
//FUNCIONES SETTERS Y GETTERS

    //Setter's
    
public function SetFecha($fecha){
        
$this->vfecha $fecha;
    }
    public function 
SetHora($hora){
        
$this->vHora $hora;
    }
    public function 
SetDia($dia){
        
$this->vDia $dia;
    }
    public function 
SetMes($mes){
        
$this->vMes $mes;
    }
    public function 
SetAnio($anio){
        
$this->vAnio $anio;
    }

    
//Getter's
    
public function GetFecha(){
        return 
$this->vFecha;
    }
    public function 
GetHora(){
        return 
$this->vHora;
    }    
    public function 
GetDia(){
        return 
$this->vDia;
    }
    public function 
GetMes(){
        return 
$this->vMes;
    }
    public function 
GetAnio(){
        return 
$this->vAnio;
    }

       }

?>
Luego tengo otra clase llamada Cliente
Código:
Código PHP:
<?php
//ARCHIVO cliente.php
include_once('basedatos.php');
include_once(
'fechas.php');

        class 
Cliente{
             private 
$vNomcliente;
         private 
$vRif;
         private 
$vNit;
         private 
$vFechaVencimiento;
         private 
$vFechaCreacion;
             
             public function 
__construct(){        
        
$this->vNomcliente $this->SetNomCliente("");
        
$this->vRif $this->SetRif("");
        
$this->vNit $this->SetNit("");
              }
            
              
//FUNCIONES SETTERS Y GETTERS

          //Setter's
              
public function SetNomCliente($nomCte){
        
$this->vNomcliente $nomCte;
          }
          public function 
SetRif($rif){
        
$this->vRif $rif;
          }
          public function 
SetNit($nit){
        
$this->vNit $nit;
          }
 
              
//Getter's    
            
public function GetNomCliente(){
        return 
$this->vNomcliente;
              }
          public function 
GetRif(){
        return 
$this->vRif;
          }
           public function 
GetNit(){
        return 
$this->vNit;
          }
               
              public function 
AgregarCliente(){
                   
$bd = new BaseDatos();
                   
$fechaCreacion = new Fechas();
                   
$fechaVencimiento = new Fechas();
                   
                   
$query "insertarCliente('".trim($this->GetNomCliente())."',
                                                     '"
.trim($this->GetRif())."',
                                                     '"
.trim($this->GetNit())."',
                                                     '"
.trim($fechaCreacion->GetFecha())."',
                                                     '"
.trim($fechaVencimiento->GetFecha())."');";
                   
$bd->Conexion();
                      
$resultado =  $bd->EjecutarQuery($query);                                                                  
                   
$bd->Desconexion();
                   return 
$resultado;                                      
              }
        }
     
?>
Despues tengo un el siguiente archivo
Código:
Código PHP:
//ARCHIVO agregarCliente.php
<?php
include_once('cliente.php');
include_once(
'fecha.php');

    
$cliente = new Cliente();
    
$fechaCreacion = new Fechas();
    
$fechaVencimiento = new Fechas();

    
$cliente->SetNomCliente($_POST['nombreCliente']);
    
$cliente->SetRif($_POST['rif']);
    
$cliente->SetNit($_POST['nit']);
    
    
$fechaCreacion->SetFecha($_POST['fechaCreacion']);
    
$fechaVencimiento->SetFecha($_POST['fechaVenc']);

    echo 
$cliente->AgregarCliente(); // Me arroja un mensaje de error a través de un alert
?>
Ahora fijense que en el archivo agregarCliente.php tengo dos instancias de la clase Fechas, mi pregunta es cuando en el método de agregarCliente() en el archivo cliente.php tengo los getters de las fechas cómo sabe que es valor le corresponde Huh?

Espero haberme explicado mejor.
Gracias de Antemano