1

我目前正在为我的发票使用一个名为 MyClientBase 的开源解决方案,一切都运行良好。

通常,当我为客户生成发票时,我可以将其作为 PDF 或电子邮件(或 HTML)。在生成 HTML 发票时,指向它的链接是安全的(只有登录的用户才能查看发票),所以我正在尝试制作可公开查看的发票,该发票会生成我们可以在电子邮件中发送的 md5-html。

现在它通过在正确的文件夹中生成一个 md5-html 文件来工作,一切都很好,除了 html 文件是空的。我已经在文件夹上将 CHMOD 设置为 777 并尝试了几种解决方案,但没有任何效果。相反,它会在同一页面上生成两张发票(重复),并将 html 文件留空。所以我认为一些熟练的 php/html-guy 可能会解决这个问题。

这是我现在正在使用的代码:

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 ---------------------------  */
     }

我很感激我能得到的任何帮助!

4

2 回答 2

1

试试这个,它应该可以工作,它的作用是获取输出,并将其存储在一个变量中,然后这个变量将是该文件的内容它可能需要一些调整告诉我你是否有任何错误

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 ---------------------------  */
     }
于 2012-04-17T10:38:26.170 回答
1

在“评论讨论”之后,问题来自不包含发票 HTML 的 $template。

$this->load->view('invoice_templates/default_template'); 的结果 不包含 HTML,但可能仅包含状态代码。

我认为您可以朝这个方向搜索。

于 2012-04-17T10:39:06.673 回答