0

我有员工应用程序,其中用户可以辞职,活跃,新和转移。我想要实现的是,当员工的地位从活动(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'));
4

1 回答 1

0

You're using $this->Employee->getLastInsertID(), which will only be present after inserting a new Employee.

Because you're editing an existing Employee, this will always be empty. You should use the $id in stead;

$this->_sendNewEmployeeEditMail($id);
于 2013-03-03T11:47:35.033 回答