Foros del Web » Programando para Internet » PHP »

Problema en constructor

Estas en el tema de Problema en constructor en el foro de PHP en Foros del Web. Hola, buenos dias, disculpen si la inquietud les parece muy obvia pero tengo un problema con el constructor de una clase que he creado, la ...
  #1 (permalink)  
Antiguo 20/02/2011, 09:00
Avatar de ichizuke  
Fecha de Ingreso: diciembre-2008
Mensajes: 11
Antigüedad: 15 años, 4 meses
Puntos: 0
Pregunta Problema en constructor

Hola, buenos dias, disculpen si la inquietud les parece muy obvia pero tengo un problema con el constructor de una clase que he creado, la clase tiene el objetivo de generar un archivo en PDF para generar reportes, el caso es que utilizo 2 variables dentro de la clase en varias funciones, el problema como tal es que en el momento de invocar el contructor y tratar de inicializar las variables me sale el siguiente error:

Notice: Undefined variable: valor in C:\wamp\www\Meganet\Reportes\ventas\generar_report e.php on line 13

Fatal error: Cannot access empty property in C:\wamp\www\Meganet\Reportes\ventas\generar_report e.php on line 13

adjunto el codigo y agradezco de antemano cualquier solucion que permita saltar este problema.

Código PHP:
<?php 
    
require("../../Clases/FPDF/fpdf.php");
    require(
"../../Clases/OCBD_mysql_class.php");
    
    
    class 
PDF extends FPDF{
    
        var 
$obj_conector;
        var 
$valor;
        
        function 
PDF(){
            
parent::FPDF();
            
$this->$valor="";
            
$this->$obj_conector=new OCBD_mysql("meganet");
            
$this->$obj_conector->conectar();
        }
        function 
Header(){
            
//Logo
            
$this->Image("logo.jpg",13,10,33);
            
//Feunte Arial Bold 15
            
$this->SetFont("Arial","B",15);
            
//Moverse a la derecha
            
$this->Cell(41);
            
//Titulo
            
if($this->$valor==""){
                
$this->Cell(160,10," Reporte: Ventas registradas en el sistema","LTR",0,"C");
            }
            else{
                
$sql="SELECT nomcli_cli,apecli_cli FROM clientes WHERE idecli_cli =\"$valor\"";
                
$resultado=$this->$obj_conector->query_exe($sql);
                
$fila=mysql_fetch_array($resultado);
                
$this->Cell(160,10,"Reporte: Ventas realizadas a: ".$fila["nomcli_cli"]." ".$fila["apecli_cli"],"LRT",0,"C");
            }
            
$this->Ln();
            
$this->Cell(41);
            
$this->SetFont("Arial","B",10);
            
$this->Cell(160,10,"Fecha:".date("d-m-Y")." Hora:".date("H:i:s"),"LRB",0,"C");
            
//Salto de linea
            
$this->Ln(20);
        }
        
        function 
Tabla()
        {
            
//Colores, ancho de línea y fuente en negrita
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetFont('','B');
            
//Cabecera
            
$this->Cell(200,9,"Datos Factura",1,1,"C",1);
            
            
$this->SetFillColor(255);
            
$this->SetTextColor(0,0,255);
            
$this->SetFont('','');
            
            
$this->Cell(30,8,"Nº Factura",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
$this->Cell(30,8,"Fecha",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
$this->Ln();
            
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetFont('','B');
            
            
$this->Cell(200,9,"Datos Cliente",1,1,"C",1);
            
            
$this->SetFillColor(255);
            
$this->SetTextColor(0,0,255);
            
$this->SetFont('','');
            
            
$this->Cell(30,8,"Identificacion",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
$this->Cell(30,8,"Telefono",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
            
$this->Ln();
            
            
$this->Cell(30,8,"Nombre",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
$this->Cell(30,8,"Apellido",1,0,"L",1);
            
$this->Cell(70,8,"",1,0,"L",0);
            
            
$this->Ln();
            
            
$this->SetFillColor(255,0,0);
            
$this->SetTextColor(255);
            
$this->SetFont('','B');
            
$this->Cell(200,9,"Articulos",1,1,"C",1);
            
            
$this->SetFont('','',10);
            
$w=array(15,40,70,15,30,30);
            
$encabezado=array("Codigo","Nombre","Descripcion","Cantidad","Valor Unitario","Valor Total");
            for(
$i=0;$i<count($encabezado);$i++)
                
$this->Cell($w[$i],7,$encabezado[$i],1,0,'C',1);
            
/*
            $this->Ln();
            //Restauración de colores y fuentes
            $this->SetFillColor(224,235,255);
            $this->SetTextColor(0);
            $this->SetFont('');
            //Datos
            $fill=false;
            while($fila=mysql_fetch_array($resultado_sql))
            {    
                for($i=0;$i<count($encabezado);$i++)
                    $this->Cell($w[$i],6,$fila[$i],"LR",0,"L",$fill);
                $this->Ln();
                $fill=!$fill;
            }
            $this->Cell(array_sum($w),0,'','T');
            */
        
}
        
        function 
GeneraTablas($consulta_sql){
        
        }
        
        function 
Footer(){
            
$this->AliasNbPages();
            
//Posicion: 1,5 cm del final
            
$this->SetY(-15);
            
//Fuente Arial Italic 8
            
$this->SetFont("Arial","I",8);
            
//Numero de pagina
            
$this->Cell(0,10,"Pagina ".$this->PageNo().'/{nb}',0,0,"C");
            
$this->SetY(-25);
            
$this->SetFont("Arial","IB",8);
            if(
$this->$valor==""){
                
$sql="SELECT * FROM ventas";
                
$total_ventas=0;
                
$resultado=$this->$obj_conector->query_exe($sql);
                
$this->Cell(0,4,"Numero total de ventas registradas: ".mysql_num_rows($resultado),"LRT",0,"C");
                while(
$fila=mysql_fetch_array($resultado)){
                    
$total_ventas+=$fila["totalv_ven"];
                }
                
$this->Ln();
                
$this->Cell(0,4,"Valor total de ventas registradas: $".number_format($total_ventas,0,",","."),"LRB",0,"C");
                
            }
            else{
                
$sql="SELECT * FROM ventas WHERE idecli_ven=\"$valor\"";
                
$sql2="SELECT * FROM clientes WHERE idecli_cli=\"$valor\"";
                
$resultado=$this->$obj_conector->query_exe($sql);
                
$resultado2=$this->$obj_conector->query_exe($sql2);
                
$fila=mysql_fetch_array($resultado2);
                
$total_ventas=0;
                
$this->Cell(0,4,"Numero total de ventas registradas a ".$fila["nomcli_cli"]." ".$fila["apecli_cli"].": ".mysql_num_rows($resultado),"LRT",0,"C");
                
                while(
$fila=mysql_fetch_array($resultado)){
                    
$total_ventas+=$fila["totalv_ven"];
                }
                
$sql2="SELECT * FROM clientes WHERE idecli_cli=\"$valor\"";
                
$resultado2=$this->$obj_conector->query_exe($sql2);
                
$fila=mysql_fetch_array($resultado2);;
                
$this->Ln();
                
$this->Cell(0,4,"Valor total de ventas registradas a ".$fila["nomcli_cli"]." ".$fila["apecli_cli"].": $".number_format($total_ventas,0,",","."),"LRB",0,"C");
            }
        }
    }
    
    
$pdf=new PDF();
    
$obj_conector=new OCBD_mysql("meganet");
    
$valor=$_POST["valor_parametro"];
    
$resultado="";
    
$obj_conector->conectar();
    
$pdf->AddPage("P","Legal");
    
$pdf->SetFont("Times","",12);
    
    
$pdf->Tabla();
    
/*
    $encabezado=array("Identificacion","Apellido","Nombre","Direccion","Ciudad","Telefono","Correo","Fecha Registro");
    
    if($valor==""){
        $sql="SELECT idecli_cli,apecli_cli,nomcli_cli,dircli_cli,codciu_cli,telcli_cli,emacli_cli,feincl_cli FROM clientes ORDER BY feincl_cli";
        $resultado=$obj_conector->query_exe($sql);
    }
    else{
        $sql="SELECT idecli_cli,apecli_cli,nomcli_cli,dircli_cli,codciu_cli,telcli_cli,emacli_cli,feincl_cli FROM clientes WHERE codciu_cli =\"$valor\"";
        $resultado=$obj_conector->query_exe($sql);
    }
    
    $pdf->Tabla($encabezado,$resultado);
    */
    
$pdf->Output();

?>
  #2 (permalink)  
Antiguo 20/02/2011, 09:20
 
Fecha de Ingreso: diciembre-2010
Ubicación: valencia
Mensajes: 203
Antigüedad: 13 años, 4 meses
Puntos: 11
Respuesta: Problema en constructor

estas usando $this->$var cuando es $this->var
  #3 (permalink)  
Antiguo 20/02/2011, 09:23
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Problema en constructor

de verdad, te sugiero leer un manual...
http://www.php.net/manual/es/language.oop5.php
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #4 (permalink)  
Antiguo 20/02/2011, 09:29
Avatar de ichizuke  
Fecha de Ingreso: diciembre-2008
Mensajes: 11
Antigüedad: 15 años, 4 meses
Puntos: 0
Respuesta: Problema en constructor

Buuuu que bobada... jajajajaj muchas gracias de verdad, no se que me paso a de ser que llevo mas de un dia sin dormir y ademas no he desayunado por estar en estas...Gracias

Etiquetas: constructor, variables
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 01:07.