Problem with variable $ _GET in ajax [closed]

-4

I receive, through ajax, the variable $ temporal image, then I put it in a variable called $ data, where I send it to another function, the question is that neither of the two functions recognizes a variable that is in the url , I've tried to put in both and nothing, the funny thing is that if I remove the parameter $ data from the function showImageOfertasController ($ data) if I recognize the variable

class AjaxOC{

public $imagenTemporal;
public function GestorGaleriaOperadorCafe(){

    $datos=$this->imagenTemporal;
    $respuesta=controllerOperadorCafes::mostrarImagenOfertasController($datos);
     echo $respuesta;

}
}

public function mostrarImagenOfertasController($datos){


    list($ancho,$alto)=getimagesize($datos);

    if ($ancho < 1024 || $alto < 768) {

        echo 0;

    }else{

        $datosController=array("ruta"=>$datos,
                                "id"=>$_GET['id']);

        DatosOperadorCafe::subirImagenOfertasgaleriaModel($datosController,"galeria_ofertas_cafe");
        $respuesta=DatosTienda::mostrarImagenOfertasgaleriaModel($datosController,"galeria_ofertas_cafe");

        echo $respuesta['ruta'];

    }

}
    
asked by jorgnv 28.08.2017 в 22:04
source

1 answer

1

Expanding my comment, try it this way:

class AjaxOC {

  public $id;

  public function GestorGaleriaOperadorCafe($id)
  {
    $this->id = $id;   // Esto es opcional
    $datos = $this->imagenTemporal; // Supongo que esto lo tienes definido
    var_dump($id); //
    echo "<br>";
    $respuesta= controllerOperadorCafes::mostrarImagenOfertasController($datos, $id);
    echo $respuesta;
  }

}


if (isset($_GET['id'])) {
  $c= new AjaxOC();
  $c->GestorGaleriaOperadorCafe($_GET['id']);
}

Although for the structure that I see you are trying to handle, you should include a constructor in your class :

class AjaxOC {
  public $id;

  public function GestorGaleriaOperadorCafe()
  {
    $datos = $this->imagenTemporal;
    // var_dump($id);
    echo "<br>";
    $respuesta= controllerOperadorCafes::mostrarImagenOfertasController($datos, $id);
    echo $respuesta;
  }

  public __construct($id)
  {
    $this->id = $id;
  }
}


if (isset($_GET['id'])) {
  $c= new AjaxOC($_GET['id']);
  $c->GestorGaleriaOperadorCafe();
}
    
answered by 28.08.2017 в 23:37