Welcome Guest, Not a member yet? Register   Sign In
Can't load view as variable
#1

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.
Reply
#2

(This post was last modified: 11-26-2020, 07:10 AM by sammyskills.)

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.
Reply
#3

(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>';
}

}

Reply
#4

maybe look at: ob_start(); ob_get_contents();
Reply
#5

Read this:

HOW TO SEND EMAIL USING HTML TEMPLATES IN CODEIGNITER
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB