我有员工申请,用户可以辞职,有效,新的和转移。我想要实现的是,当一个员工的职位从活动状态(standing_id = 1)更改/编辑时,它应该能够通过电子邮件发送但不是。我在EmployeeController中放了一个电子邮件功能。以下是我的代码。
function _sendNewEmployeeEditMail($id) {
$Employee = $this->Employee->read(null,$id);
$email = new CakeEmail();
$email->from(array('no-reply@test.com' => 'Testing App'));
$email->to(array('jaahvicky@gmail.com' => 'Name Surname'));
$email->subject('New Employee');
$email->template('employee_email');
$email->viewVars(compact('Employee'));
$email->emailFormat('html');
$edit_email = true;
$current_status = $this->Employee->field('standing_id');
if($current_status==1) {
$edit_email = false;
if ($email->send()) {
$this->Session->setFlash('Your employee has been submitted.','default',array('class' => 'notification'));
return true;
} else {
$this->Session->setFlash('Your employee has not been submitted.','default',array('class' => 'error'));
return false;
}
}
}
在我的编辑保存功能中,这是我试图发送电子邮件的方式
public function edit($id = null) {
$this->Employee->id = $id;
if (!$this->Employee->exists()) {
throw new NotFoundException(__('Invalid employee'));
}
if ($this->request->is('post') || $this->request->is('put')) {
if ($this->Employee->save($this->request->data)) {
$this->Session->setFlash(__('The employee has been saved'),'default',array('class' => 'notification'));
$this->_sendNewEmployeeEditMail($this->Employee->getLastInsertID() );
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The employee could not be saved. Please, try again.'),'default',array('class' => 'error'));
}
} else {
$this->request->data = $this->Employee->read(null, $id);
}
$standings = $this->Employee->Standing->find('list');
$this->set(compact('standings'));
答案 0 :(得分:0)
您使用的是$this->Employee->getLastInsertID()
,只有在插入新员工后才会出现。
因为您正在编辑现有的员工,所以这将始终为空。你应该使用$ id;
$this->_sendNewEmployeeEditMail($id);