gpt4 book ai didi

PHP "Undefined Function"即使它实际上在同一个文件中

转载 作者:行者123 更新时间:2023-12-05 08:17:39 25 4
gpt4 key购买 nike

我在这个特定的应用程序上使用 CakePHP。通过 add() 在网站上提交博客文章时,它应该通过 pending_email() 向管理员发送通知电子邮件,但我收到以下信息错误:

fatal error :调用 .../app/controllers/blog_posts_controller.php 中的未定义函数 pending_email() 第 134 行

代码如下:

function add($blog_id = null) {
if (!empty($this->data)) {
switch ($this->params['form']['submit']) {
case 'draft':
$this->data['BlogPost']['status_id'] = DRAFT;
break;
case 'approval':
$this->data['BlogPost']['status_id'] = PENDING;
break;
case 'publish':
$this->data['BlogPost']['status_id'] = PUBLISHED;
break;
}
$this->data['BlogPost']['tags'] = $this->__tagCleanup($this->data['BlogPost']['tags']);
$this->BlogPost->create();
if ($this->BlogPost->save($this->data)) {
if ($this->data['BlogPost']['status_id'] == PUBLISHED) {
$this->__tagUp($this->data['BlogPost']['blog_id'], $this->data['BlogPost']['tags']);
}

// Send the e-mail notating that a blog is pending
pending_email($blog_id);

$this->Session->setFlash(__('The blog post has been saved', true));
$this->redirect(array('action' => 'index', $this->data['BlogPost']['blog_id']));
} else {
$this->Session->setFlash(__('The blog post could not be saved. Please, try again.', true));
}
}
// fetch blog_post context
$this->BlogPost->Blog->recursive = -1;
$blog = $this->BlogPost->Blog->read(array('id','title'),$blog_id);
$this->set('blog', $blog);

$this->data['BlogPost']['user_id'] = $this->user_id;
if (!is_null($blog_id)) {
$this->data['BlogPost']['blog_id'] = $blog_id;
}


}


function pending_email($id) {
if (!$id) {
$this->Session->setFlash(__('Invalid blog post', true));
$this->redirect(array('action' => 'index'));
}

$this->BlogPost->contain(array(
'User' => array('fields' => 'id', 'full_name', 'name', 'last_name'),
'Tag' => array('fields' => 'name'),
'BlogPostComment' => array('fields' => array('created', 'content')),
'BlogPostComment.User' => array('fields' => array('name', 'last_name')),
));

if(($blogPost = $this->BlogPost->read(null, $id)) == NULL){
$this->Session->setFlash(__('Invalid blog post', true));
$this->redirect(array('controller'=>'spotlights', 'action' => 'index'));
}

$this->set('blogPost', $this->BlogPost->read(null, $id));
$temp = $this->BlogPost->read(null, $id);
$this->BlogPost->Blog->recursive = -1;

//Blog information
$title = $temp['BlogPost']['title'];
$author = $temp['User']['full_name'];
$date_created = $temp['BlogPost']['created'];

// Properly format the excerpt
$excerpt = preg_replace("/&#?[a-z0-9]+;/i","", $temp['BlogPost']['content']);

$content = "<h2>Hello,</h2><p>$author has submitted a new blog post for review. <ul><li><b>Title:</b> $title </li><li><b>Author</b>: $author</li><li><b>Excerpt</b>: \"$excerpt\"</li><li><b>Created on:</b> $date_created</li></ul></p><p>You can log into the dashboard to approve this post.</p>";
$to = ADMIN_EMAIL;
$from = SMTP_FROM;
$subject = "New blog post submitted by $author";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $from . "\r\n" .
'Reply-To: ' . $from . "\r\n" .
'X-Mailer: PHP/' . phpversion();

//Send the e-mail
mail($to, $subject, $content, $headers);
}

出于隐私考虑,我删除了一些内容,但不应该涉及这个问题。一如既往,非常感谢任何想法!

最佳答案

由于pending_email不是全局函数,而是 Controller 上的一个方法,所以需要这样调用:

$this->pending_email($blog_id);

$this 关键字引用博客文章 Controller 类。

关于PHP "Undefined Function"即使它实际上在同一个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13037405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com