We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Views :: Unable to load the requested file

Development and Programming

Derek Jones's avatar
Derek Jones
7,561 posts
15 years ago
Derek Jones's avatar Derek Jones

I think that’s what I’m providing, but we may just be on different wavelengths this morning. Can you give a very brief pseudo-code version of what you’re describing?

       
Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

Below a function in my custom module, it creates a receipt and then sends an e-mail to the user.

I use views for the receipt and the e-mail.

If views are “no the way to do it”, how to do it otherwise?

function send_receipt(&$transaction)
{
    // EE settings to allow PDF output
    $this->EE =& get_instance();
    $this->EE->load->helper('url');
    $this->EE->load->_ci_view_path = PATH_THIRD.'crm/views/';    
    require_once(PATH_THIRD."module/includes/dompdf/dompdf_config.inc.php");
    
    $transaction->invoice_number = $this->new_invoice_number($transaction->transaction_id);
    
    $view['transaction'] =& $transaction;
    
    $html = $this->EE->load->view('invoice',$view,TRUE);
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
            
    $pdf = $dompdf->output();
    
    $file = str_replace('ee/',"receipts/receipt_".$transaction->invoice_number.".pdf",BASEPATH);
    
    if(file_exists($file))
        unlink($file);
    
    file_put_contents($file, $pdf);
    
    $email_text = $this->EE->load->view('messages/receipt',$view,TRUE);
    
    $this->EE->load->library('email');
    $this->EE->email->wordwrap = true;
    $this->EE->email->from('[email protected]', 'Company name');
    $this->EE->email->to($transaction->email);
    $this->EE->email->bcc('[email protected]');
    $this->EE->email->subject('Receipt');
    $this->EE->email->message($email_text);
    $this->email->attach($file);
    $this->EE->email->Send();

    $this->EE->load->_ci_view_path = APPPATH.'views/';

    return $file;
}

Thanks for your fast replies!

       
Derek Jones's avatar
Derek Jones
7,561 posts
15 years ago
Derek Jones's avatar Derek Jones

Is this triggered via an action request or a tag in a template? What’s the context in which this method is called, in other words?

       
Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

Through an action request.

       
Derek Jones's avatar
Derek Jones
7,561 posts
15 years ago
Derek Jones's avatar Derek Jones

If you used the Template class, you would actually gain some functionality in your module’s emails, the ability to use EE tags, global variables, etc. I’m heading to lunch but when I get back I can work up an example for you.

       
Derek Jones's avatar
Derek Jones
7,561 posts
15 years ago
Derek Jones's avatar Derek Jones

Ok, here’s a simple example

// the second and third parameter aren't necessary, but I've used it here
// so that the syntax is consistent with the rest of the module code (->TMPL)
$this->EE->load->library('Template', NULL, 'TMPL');

$this->EE->TMPL->fetch_and_parse('invoice', 'email');
$email_text = $this->EE->TMPL->parse_globals($this->EE->TMPL->final_template);

// at this point, the 'email' template from the 'invoice' template group has been parsed, along with
// any ExpressionEngine tags and global variables on the template

// parse the variables for this transaction - using parse_variables_row() in this example
// since that appears to match the intent of your data
$email_text = $this->EE->TMPL->parse_variables_row($email_text, $transaction);

// and now it's ready to email
       
Frans Cooijmans's avatar
Frans Cooijmans
36 posts
15 years ago
Frans Cooijmans's avatar Frans Cooijmans

Thanks, definitely going to use that.

Only argument against using this is that users can possibly destroy the templates, but that’s always a risk.

In the end I still think using views from a module can be very useful, any chance this is going to be supported in the future (maybe already in the 2.1 release, haven’t tested that)?

       
Derek Jones's avatar
Derek Jones
7,561 posts
15 years ago
Derek Jones's avatar Derek Jones

No, it’s not planned; if you need to lock down who can edit the template, that is set in the member group preferences.

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.