title: Passing data from model to print into tcpdf in codeigniter
body: <p>I'm trying to create a pdf file with some data in that I get from a query, the pdf creator is in the controller (TCPDF). </p>
  
  <p>My storyboard :
  I am using codeigniter to develop my php application. In my view, there is a table that every row have a button to create a pdf from information its row. I can preview it in modal bootstrap. 
  Now , I am confused how to passed that information to pdf (TCPDF). 
  Should i using GET or somrthing like that in my Controller ?
  Or in modal ?</p>
  
  <p>This is my view</p>
  
  <pre><code>&lt;tbody&gt;
    &lt;?php
      $no = 1;
      foreach($data_request as $data) {
    ?&gt;
     &lt;tr&gt;
          &lt;td class="center"&gt;&lt;?php echo $no++.". ";?&gt; &lt;/td&gt;                                           
          &lt;td class="sorting1"&gt;&lt;?php echo $data['id_request'];?&gt; &lt;/td&gt;
          &lt;td class="center"&gt;&lt;?php echo "$name"; ?&gt;&lt;/td&gt;
          &lt;td class="center"&gt;&lt;?php echo date ("d-m-Y, H:i ",strtotime($data['time_start']));?&gt;&lt;/td&gt;
          &lt;td class="center"&gt;&lt;?php echo $data['keluhan'];?&gt;&lt;/td&gt;                                            
          &lt;td class="center"&gt;&lt;span class="label label-warning"&gt;&lt;?php echo $data['status_request'];?&gt;&lt;/span&gt;&lt;/td&gt; 
          &lt;td class="center"&gt;&lt;?php echo date ("d-m-Y, H:i ",strtotime($data['close_request']));?&gt;&lt;/td&gt;                                                     &lt;td  class="center"&gt;
                  &lt;a class="btn btn-danger" href="#"&gt;
                      &lt;i class="halflings-icon white trash"&gt;&lt;/i&gt; Close
                  &lt;/a&gt;
  
                  &lt;a class="btn btn-success" href="#" id="print" req_id="&lt;?php echo $data['id_request']; ?&gt;"&gt;
                      &lt;i class="halflings-icon pencil"&gt;&lt;/i&gt; Print  
                  &lt;/a&gt;         
          &lt;/td&gt;
     &lt;/tr&gt;
  
     &lt;?php } ?&gt;
     &lt;/tbody&gt;
  
  //This is my modal bootstrap preview :
  &lt;div class="modal hide fade" id="myModal"&gt;
  
          &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal"&gt;×&lt;/button&gt;
              &lt;h1&gt;Print Preview&lt;/h1&gt;
          &lt;/div&gt;
  
          &lt;div class="modal-body"&gt;
             &lt;p id="id_preview"&gt; &lt;/p&gt;
          &lt;/div&gt;
  
          &lt;div class="modal-footer"&gt;
               &lt;?php $id= $data['id_request'];?&gt;
               &lt;a href="&lt;?php echo base_url().'control_closing/generate_pdf/id'; ?&gt;" class="btn btn-primary"&gt;Jadikan PDF&lt;/a&gt;
              &lt;a href="#" class="btn" data-dismiss="modal"&gt;Close&lt;/a&gt;   
          &lt;/div&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>This is my controller</p>
  
  <pre><code>public function generate_pdf($idRequest){
      $this-&gt;model_request-&gt;selectOneRequest($idRequest);
      $this-&gt;load-&gt;library("TC_PDF");
      $pdf = new TC_Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  
      // set document information
      $pdf-&gt;SetCreator(PDF_CREATOR);
      $pdf-&gt;SetAuthor('Dzil');
      $pdf-&gt;SetTitle('Form Perbaikan / Permintaan');
      $pdf-&gt;SetSubject('TMS/DEPT/IT/06');
      $pdf-&gt;SetKeywords('TCPDF, PDF, form, perbaikan, Permintaan');
  
      // set default header data
      $pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
  
      // set header and footer fonts
      $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
      $pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  
      // set default monospaced font
      $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  
      // set margins
      $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
      $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
      $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  
      // set auto page breaks
      $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  
      // set image scale factor
      $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
      // set some language-dependent strings (optional)
      if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
          require_once(dirname(__FILE__).'/lang/eng.php');
          $pdf-&gt;setLanguageArray($l);
      }
  
      // ---------------------------------------------------------
  
      // set font
      $pdf-&gt;SetFont('helvetica', '', 12);
  
      // add a page
      $pdf-&gt;AddPage();
      $pdf-&gt;Ln(8);
  
      $pdf-&gt;Cell(30, 5, 'Nama', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 5, '$data_pdf[nama]', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
  
  
      $pdf-&gt;Cell(30, 5, 'Departement', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
  
  
      $pdf-&gt;Cell(30, 5, 'NIK', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 5, '', "B", 1, 'L', 0, '', 0, false, 'T', 'C');
  
      $pdf-&gt;Ln(4);
  
  
      $pdf-&gt;Cell(30, 5, 'Permintaan / ', 0, 1, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(30, 5, 'Perbaikan  ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
  
      $html = &lt;&lt;&lt;EOD
  
      &lt;form action=""&gt;
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; &amp;nbsp; Login    
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; &amp;nbsp; Printer
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; &amp;nbsp; Monitor
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; &amp;nbsp; Computer
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; &amp;nbsp; Network
          &lt;input type="checkbox" name="request[]" id="Login" value="Login" &gt; Lain-lain
      &lt;/form&gt;
   EOD;
  
      $pdf-&gt;writeHTML($html, true, 1, false, 1);        
  
  
      $pdf-&gt;Ln(4);
      $pdf-&gt;Cell(30, 10, 'Keluhan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 90,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
  
      $pdf-&gt;Cell(30, 10, 'Keterangan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 60,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
  
      $pdf-&gt;Cell(30, 10, 'Catatan', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell( 2, 5, ': ', 0, 0, 'L', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell( 0, 10,' ', 0, 1, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Ln(4);
  
      $pdf-&gt;SetFont('helvetica', '', 8);
      $pdf-&gt;Cell(30, 5, 'Tgl Permintaan / Paraf', 1, 0, 'C', 0, '', 0, false, 'T', 'C'); //width, height, 
      $pdf-&gt;Cell(30, 5, 'Persetujuan Manajer', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(25, 5, 'Tgl Persetujuan', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(25, 5, 'Diterima Oleh', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(25, 5, 'Tgl Terima', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(25, 5, 'Perkiraan Selesai', 1, 0, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(25, 5, 'Tgl Selesai', 1, 1, 'C', 0, '', 0, false, 'T', 'C');
      $pdf-&gt;Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T'); //width, height, 
      $pdf-&gt;Cell(30, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell(25, 25, '', 1, 0, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Cell(25, 25, '', 1, 1, 'L', 0, '', 0, false, 'T', 'T');
      $pdf-&gt;Ln(2);
      $pdf-&gt;SetFont('helvetica', '', 8);
      $pdf-&gt;Cell(0, 0, 'TMS-IT-06 (10.2001)', 0, 0, 'L', 0, '', 0, false, 'T', 'T');
  
      // reset pointer to the last page
      $pdf-&gt;lastPage();
  
      // ---------------------------------------------------------
  
      //Close and output PDF document
      $pdf-&gt;Output('example_057.pdf', 'I');
  
  
  }
  </code></pre>
  
  <p>This is my model</p>
  
  <pre><code>public function selectOneRequest($id_request){
     $query = $this-&gt;db-&gt;get_where('tbl_request', array('id_request'=&gt;$id_request));
      return $query-&gt;result_array();
  }
  </code></pre>