2011-06-15 90 views
0

我想從CakePHP控制器發送電子郵件與當前正在添加的帖子的網址。我需要找到帖子的ID,以便它可以傳遞給視圖函數,但我不知道這一點?CakePHP發送電子郵件與最近發佈的網址

即,

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 = '[email protected]'; 
     $this->Email->subject = 'Cake test template email'; 
     $this->Email->replyTo = '[email protected]'; 
     $this->Email->from = 'Cake Test Account <[email protected]>'; 
     $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

$this->Post->id將包含最後插入的ID。那是你在找什麼?

+0

是的!真棒。謝謝 – benhowdle89 2011-06-15 22:08:23

+0

不客氣。如果我回答了您的問題,請「接受」它。 – 2011-06-15 22:11:46

+0

老兄,我有3,980點,我知道如何接受答案:)只是等待時間限制解除 – benhowdle89 2011-06-15 22:13:24