Pregunta

I'm currently using a open source solution for my invoices called MyClientBase and everything is working really well.

Normally when I generate an invoice to a client, I can either do it as a PDF or e-mail (or HTML). When generating the HTML-invoice the link to it is secure (only logged in users can view the invoice) so I'm trying to make publicly viewable invoices that generates a md5-html that we can send in the e-mails.

Right now it's working by generating a md5-html file in the right folder and everything is great, except that the html-file is empty. I've set the CHMOD to 777 on the folder and tried several solutions but nothing really works. Instead it generates two invoices (duplicates) on the same page and leaves the html-file empty. So I think some skilled php/html-guy might figure this one out.

Here's the code I'm using right now:

function generate_html() {

$invoice_id = uri_assoc('invoice_id');

$this->load->library('invoices/lib_output');

$this->load->model('invoices/mdl_invoice_history');

$this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('generated_invoice_html'));

$this->lib_output->html($invoice_id, uri_assoc('invoice_template'));

 /*  ------------------ GENERATE MD5-HTML ---------------------------  */
     $file = md5('my_output_path'.$invoice_id).'.html';

     echo "<a href='my_output_path".$file."'>Link to client invoice</a>";
     $f = fopen('my_invoice_path'.$file, 'w');
     $template = $this->load->view('invoice_templates/default_template');
 fwrite($f, $template);true;    
     /*  ------------------ End generate md5 ---------------------------  */
     }

I appreciate any help I can get!

¿Fue útil?

Solución

try this, it should work, what it does is it fetches the output, and store it in a variable then this variable will be the content of that file it might need some tweaks tell me if you get any errors

function generate_html() {

$invoice_id = uri_assoc('invoice_id');

$this->load->library('invoices/lib_output');

$this->load->model('invoices/mdl_invoice_history');

$this->mdl_invoice_history->save($invoice_id, $this->session->userdata('user_id'), $this->lang->line('generated_invoice_html'));

$this->lib_output->html($invoice_id, uri_assoc('invoice_template'));

 /*  ------------------ GENERATE MD5-HTML ---------------------------  */
     $file = md5('my_output_path'.$invoice_id).'.html';

     echo "<a href='my_output_path".$file."'>Link to client invoice</a>";
     $f = fopen('my_invoice_path'.$file, 'w');
     ob_start(); // start output buffer flow
     $old_content = ob_get_contents();
     ob_clean();
     $this->load->view('invoice_templates/default_template');
     $template = ob_get_contents(); // assign buffer contents to variable
     ob_end_clean(); // end buffer and remove buffer contents
     fwrite($f, $template);true;   
     echo $old_content;

     /*  ------------------ End generate md5 ---------------------------  */
     }

Otros consejos

After "comment discusion", the problem come from the $template that not contain the HTML of your invoice.

The result of $this->load->view('invoice_templates/default_template'); does not contain HTML but, perhaps, only a status code.

I think you can search in this direction.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top