Ver Mensaje Individual
  #7 (permalink)  
Antiguo 11/12/2015, 18:11
Avatar de detective_jd
detective_jd
 
Fecha de Ingreso: abril-2011
Ubicación: Salto
Mensajes: 437
Antigüedad: 13 años
Puntos: 6
Respuesta: problema al cargar FPDF con MVC

Hola a todos, acabo de recordar la frase de: "si no puedes con tu enemigo, unitele" bueno si funciona en un controlador entonces creo un controlador sólo para pdf:

Código PHP:
Ver original
  1. <?php
  2. require_once './App/Controller.php';
  3. require_once './Model/VehiculoModel.php';
  4. require_once './Lib/fpdf/fpdf.php';
  5. class PdfController extends Controller
  6. {
  7.     private $pdf;
  8.     private $mod_v;
  9.     function __construct() {
  10.         parent::__construct();
  11.         $this->pdf = new FPDF();
  12.         $this->mod_v = new VehiculoModel();
  13.     }
  14.     private function getPDF(){
  15.         return $this->pdf;
  16.     }
  17.     public function rep_vehiculos(){
  18.         if(Session::get("tipo") == "admin"){
  19.             Session::set('pdf', $this->getPDF());
  20.             $this->getPDF()->AddPage();
  21.             $this->getPDF()->SetFont('Arial','B',16);
  22.             $this->getPDF()->Cell(40,10,utf8_decode('Reporte de Vehículos'));
  23.             $this->getPDF()->Ln(15);
  24.             $this->getPDF()->SetFont('Arial','B',12);
  25.             $this->getPDF()->Cell(30,5,utf8_decode('Vehículo'),1);
  26.             $this->getPDF()->Cell(30,5,utf8_decode('Matrícula'),1);
  27.             $this->getPDF()->Cell(30,5,'Cantidad',1);
  28.             $this->getPDF()->Cell(30,5,utf8_decode('Descripción'),1);
  29.             $this->getPDF()->Cell(40,5,'Modelo',1);
  30.             $this->getPDF()->Cell(30,5,'Tipo',1);
  31.             $this->getPDF()->Ln(8);
  32.             foreach ($this->mod_v->obtenerTodos() as $vehiculo){
  33.                 $this->getPDF()->Cell(30,5,$vehiculo['id'],1);
  34.                 $this->getPDF()->Cell(30,5,$vehiculo['mat'],1);
  35.                 $this->getPDF()->Cell(30,5,$vehiculo['cant'],1);
  36.                 $this->getPDF()->Cell(30,5,$vehiculo['des'],1);
  37.                 $this->getPDF()->Cell(40,5,$vehiculo['modelo'],1);
  38.                 $this->getPDF()->Cell(30,5,utf8_decode($vehiculo['tipov']),1);
  39.                 $this->getPDF()->Ln(5);
  40.             }
  41.             $this->getPDF()->Output();
  42.         }
  43.         else {
  44.             Session::set("msg","Debe ser administrador para acceder.");
  45.             $this->redirect(array('Main','index.php'));
  46.         }
  47.     }
  48. }

No era lo que quería que le vamos a hacer "es lo que hay", gracias a todos. Saludos