CakePHP使用最近的帖子发送电子邮件

时间:2011-06-15 22:04:11

标签: php cakephp

我正在尝试从CakePHP控制器发送一封电子邮件,其中包含当前帖子的网址。我需要找到帖子的id,以便它可以将它传递给视图函数,但我不知道吗?

    function add() {
        if (!empty($this->data)) {
            //var_dump($this->data);
            //die();
            $file_path = $this->Attachment->upload($this->data['Post'],'img');
            //$this->Attachment->thumbnail($this->data['Post']['img'], 'attachments/files_dir', '250', '250', $crop = 'resize');
            if ($this->Post->save($this->data)) {
                $this->sendTemplateHtmlMail();
                $this->Session->setFlash('Your post has been saved.');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

    function sendTemplateHtmlMail($recipientemail, $to) { 
        $this->Email->to = 'test@gmail.com'; 
        $this->Email->subject = 'Cake test template email'; 
        $this->Email->replyTo = 'noreply@example.com'; 
        $this->Email->from = 'Cake Test Account <noreply@example.com>'; 
        $this->Email->template = 'test2'; 
        //Send as 'html', 'text' or 'both' (default is 'text') 
        $this->Email->sendAs = 'html'; 
        //Set view variables as normal 
        $this->set('recipientemail', ); 
        //Do not pass any args to send() 
        if ( $this->Email->send() ) { 
            $this->Session->setFlash('Template html email sent'); 
        } else { 
            $this->Session->setFlash('Template html email not sent'); 
        } 
//        $this->redirect('/'); 

    } 

所以我正在添加/保存帖子,然后向收件人发送电子邮件,在电子邮件中我想要刚刚添加的帖子的网址,如果我不知道它,我如何传递帖子的ID?

由于

1 个答案:

答案 0 :(得分:1)

$this->Post->id将包含最后插入的ID。那是你在找什么?