Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP使用最近发布的url发送电子邮件_Php_Cakephp - Fatal编程技术网

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

CakePHP使用最近发布的url发送电子邮件,php,cakephp,Php,Cakephp,我正在尝试从CakePHP控制器发送一封电子邮件,其中包含正在添加的当前帖子的url。我需要找到该职位的id,以便它可以传递给查看功能,但我不知道 即 函数添加(){ 如果(!empty($this->data)){ //变量转储($this->data); //模具(); $file_path=$this->Attachment->upload($this->data['Post'],'img'); //$this->Attachment->缩略图($this->data['Post']['i

我正在尝试从CakePHP控制器发送一封电子邮件,其中包含正在添加的当前帖子的url。我需要找到该职位的id,以便它可以传递给查看功能,但我不知道

函数添加(){
如果(!empty($this->data)){
//变量转储($this->data);
//模具();
$file_path=$this->Attachment->upload($this->data['Post'],'img');
//$this->Attachment->缩略图($this->data['Post']['img'],'attachments/files_dir','250','250',$crop='resize');
如果($this->Post->save($this->data)){
$this->sendTemplateHtmlMail();
$this->Session->setFlash('您的帖子已保存');
$this->redirect(数组('action'=>'index'));
}
}
}
函数sendTemplateHtmlMail($recipientemail,$to){
$this->Email->to=test@gmail.com'; 
$this->Email->subject='蛋糕测试模板Email';
$this->Email->replyTo='snoreply@example.com'; 
$this->Email->from='Cake Test Account';
$this->Email->template='test2';
//以“html”、“文本”或“两者”的形式发送(默认为“文本”)
$this->Email->sendAs='html';
//将视图变量设置为正常值
$this->set('recipientemail',);
//不要传递任何要发送的参数()
如果($this->Email->send()){
$this->Session->setFlash('Template html email sent');
}否则{
$this->Session->setFlash('Template html email not sent');
} 
//$this->redirect('/');
} 
因此,我正在添加/保存一篇文章,然后向收件人发送一封电子邮件。在电子邮件中,我想要刚刚添加的文章的url,如果我还不知道,如何传递该文章的id


谢谢

$this->Post->id
将包含最后插入的id。这就是您要找的吗?

不客气。如果我回答了你的问题,请“接受”它。老兄,我有3980分,我知道如何接受答案:)只是等待时间限制来提升我的道歉。。。我对堆栈溢出非常陌生。我不知道有时间限制。不用担心:),它会阻止你在问了问题后立即接受答案。谢谢你的回答
    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('/'); 

    }