如何从模型中获取值以及如何在控制器中使用
问题描述:
如何从模型中获取值以及如何在控制器中使用?我正尝试从发送电子邮件的数据库中获取电子邮件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'] = '[email protected]';
$config['smtp_pass'] = '[email protected]';
$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('[email protected]', 'Himagri');
$this->email->to('[email protected]');//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();
}
答
$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();
}
上作为托运
答
回报从模型结果如下:
return $query->row();
并在控制器中调用该函数并获取数据。
$resultt = $this->Products_model->delete_mail($id);
$data['productemail'] = $resultt->email;
答
尝试增加您的加入标签空间的文档https://www.codeigniter.com/userguide3/database/query_builder.html
$this->db->join('comments', 'comments.id = blogs.id');