Question

I am working with html2pdf (dompdf library), to create a PDF invoice with data from the database.

The pdf is generated with all the formatting css perfectly.

The generated pdf does not show the results of the invoice from the database, in the view I put an "else" statement to see if it was printing actually post something. it is printed empty rows.

The data in the database are there.

Where am I wrong?

Sorry for the bad English. Thank you.

My Controller:

public function index()
{

    //Load the library
    $this->load->library('html2pdf');
        $this->load->model('model_fatture2');

    //Set folder to save PDF to
    $this->html2pdf->folder('./assets/pdfs/');

        // change name file
        $nome_file = "pippo";

    //Set the filename to save/download as
    $this->html2pdf->filename($nome_file.'.pdf');

    //Set the paper defaults
    $this->html2pdf->paper('a4', 'portrait');

        $data['result_fatture'] = $this->model_fatture2->getFattureUtente();

        // test view
    $data = array(
        'title' => 'PDF Created',
        'message' => 'Hello World!'
    );

    //Load html view
    $this->html2pdf->html($this->load->view('pdf', $data, true));

    if($this->html2pdf->create('download')) {
        //PDF was successfully saved or downloaded
        echo 'PDF saved';
    }
 //$this->output->enable_profiler(TRUE);    
} 

My Model:

function getFattureUtente() {
     $userId = $this->session->userdata('id');
     $ProgettoId = $this->session->userdata('id_progetto');
     $data = array();

     $this->db->select('*'); 
     $this->db->from('fatture');
     $this->db->join('users', 'fatture.id_progetto = users.id_progetto');
     $this->db->where('id_user',$userId);
     $this->db->where('fatture.id_progetto', $ProgettoId);


     $query = $this->db->get();

     if($query->num_rows() > 0){ 
     foreach ($query->result_array() as $row) {
        $data[] = $row;
    }
    $query->result();
    return $data;
    }
    }

My View

<?php if (!empty($result_fatture)): ?>
            <?php foreach ($result_fatture as $row): ?>
            <?php if ($this->session->userdata('id') === $row['id']): ?>
            <table height="20" border="0" cellpadding="0" cellspacing="0" class="table_riga">
                <tr>
                    <td  class="col-dx"><?=$row['id_fatture']?></td>
                    <td  class="col-dx"><?=$row['id_user']?></td>
                    <td  class="col-dx"><?=$row['id_progetto']?></td>
                    <td  class="row-bottom"><?=$row['n_progetto']?></td>
                    <td  class="col-sx"><?=$row['data_emissione']?></td>
                    <td  class="col-sx"><?=$row['n_fattura']?></td>
                    <td  class="col-sx"><?=$row['prezzo']?></td>
                </tr>
            </table>
            <?php endif; ?> 
            <?php endforeach; ?>
             <?php else: ?>
             <?php echo "rows empty"; ?>
            <?php endif; ?> 
Was it helpful?

Solution

SOLVED! I'M NOT HAD DECLARED THE SESSIONS, SO THE VIEW session-> userdata ('id') === $ row ['id']):?> RETURN FALSE. If it can help someone. thanks

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top