如何从模型中获取值以及如何在控制器中使用?我正在尝试从发送电子邮件的数据库中获取电子邮件ID。我没有收到电子邮件的归档价值。
以下是我的代码
控制器代码
function NAME(){
$resultt = $this->Products_model->delete_mail($id);
$data['productemail'] = $resultt->email;
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'mail.himagri.com';
$config['smtp_port'] = '587';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'info@himagri.com';
$config['smtp_pass'] = 'Himagri@123';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->from('info@himagri.com', 'Himagri');
$this->email->to('xxxx@gmail.com');//i want to use email id
$this->email->subject('test delete mail');
$body = $this->load->view('deletemailer', $data, TRUE);
$this->email->message($body);
$this->email->send();
echo $this->email->print_debugger();
$this->product_display($data);
}
型号代码
public function delete_mail($id) {
$this->db->select('*');
$this->db->from('supplier_registration');
$this->db->join('approve_products', 'supplier_registration.id=approve_products.supplier_id_fk');
$this->db->where('approve_products.id', $id);
$query = $this->db->get();
return $query->result();
}
答案 0 :(得分:1)
从模型返回结果如下:
return $query->row();
并在控制器中调用此函数并获取数据。
$resultt = $this->Products_model->delete_mail($id);
$data['productemail'] = $resultt->email;
答案 1 :(得分:1)
$query->row();
因为您只提取一行
public function delete_mail($id) {
$this->db->select('*');
$this->db->from('supplier_registration');
$this->db->join('approve_products', 'supplier_registration.id=approve_products.supplier_id_fk');
$this->db->where('approve_products.id', $id);
$query = $this->db->get();
return $query->row();
}
答案 2 :(得分:0)
尝试在文档https://www.codeigniter.com/userguide3/database/query_builder.html
上选中的连接标记上添加空格 $this->db->join('comments', 'comments.id = blogs.id');