CodeIgniter Forums
Can't load view as variable - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Can't load view as variable (/showthread.php?tid=78071)



Can't load view as variable - calondon - 11-26-2020

I'm trying to capture a view as a variable, rather than rendering it, by setting the third argument to TRUE, but this is still rendering the page. Can anybody help? The aim is to send this in an email.

PHP Code:
$body $this->load->view('jobs/send_quote'$dataTRUE);
$this->email->message($body); 

Many thanks in advance.


RE: Can't load view as variable - sammyskills - 11-26-2020

Hi,

Are you sure you're not calling the _display() function somewhere in your code?

BTW, you should show you full code so that it can be easy to debug.


RE: Can't load view as variable - calondon - 11-26-2020

(11-26-2020, 07:01 AM)sammyskills Wrote: Hi,

Are you sure you're not calling the _display() function somewhere in your code?

BTW, you should show you full code so that it can be easy to debug.
Thanks for the speedy response. Here is the full controller, credentials removed. I appreciate it's not the cleanest code.



PHP Code:
public function send_quote ($job_id)
 {

$this->output->enable_profiler(TRUE);

if (!
$this->ion_auth->logged_in())
{
// redirect them to the login page
redirect('auth/login''refresh');
}
else {

$this->load->library('email');

$config = array();
$config['protocol']  'smtp';
$config['smtp_host'] = 'smtp.googlemail.com';
$config['smtp_user'] = '[email protected]';
$config['smtp_pass'] = 'xxxxxxxx';
$config['smtp_port'] = 465;
$config['charset']  'iso-8859-1';
$config['mailtype']  'html';
$config['newline']  '\r\n'
$config['smtp_crypto'] = 'ssl';
$config['crlf'] = '\r\n';
$config['wordwrap'] = TRUE;

$this->email->initialize($config); 



$this->email->set_header('MIME-Version''1.0; charset=utf-8');
$this->email->set_header('Content-type''text/html');



if (
$this->jobs_model->get_by_id($job_id)->email !== '') {
$to_email $this->jobs_model->get_by_id($job_id)->email;

}
else {
$data['error'] = ($this->email->print_debugger());
$this->load->view('error',$data);

}

$subject 'Quote #' $job_id;

$data['job_id'] = $job_id;
$data['jobs'] = $this->jobs_model->get_by_id($job_id);
$data['line_items_count'] = $this->orders_model->count_line_items($job_id);

if (
$data['line_items_count'] !== 0) {
echo 
'<div class="col-md bg-success text-white text-center">Line items are present.</div>';

for (
$i=0$i $data['line_items_count']; $i++) { 
$data['line_items'] = $this->orders_model->get_line_items($job_id);
}

$quote_id uniqid() . uniqid(''true);

$this->email->from($config['smtp_user'], "calondon");
$this->email->to($to_email);
$this->email->subject($subject);
$this->email->CC('[email protected]); 

$body = $this->load->view('
jobs/send_quote', $data, TRUE);

$this->email->message($body);




if($this->email->send()) {
echo '
<div class="col-md bg-success text-white text-center">Quote sent successfully.</div>';
$job_data = array ('
quote_sent' => 1, 'quote_id' => $quote_id);

$this->db->where('
job_id', $job_id);

if ($this->db->update('
jobs', $job_data)){
echo '
<div class="col-md bg-success text-white text-center">Job updated.</div>';
}
else {
echo '
<div class="col-md bg-success text-white text-center">Job could not be updated</div>';
}
}
else {
echo '
<div class="col-md bg-success text-white text-center">Email could not be sent</div>';
}

}
else {
echo '
<div class="col-md bg-success text-white text-center">There are no line items</div>';
}

}




RE: Can't load view as variable - neoneeco - 11-26-2020

maybe look at: ob_start(); ob_get_contents();


RE: Can't load view as variable - InsiteFX - 11-26-2020

Read this:

HOW TO SEND EMAIL USING HTML TEMPLATES IN CODEIGNITER