Php Joomla:onContentAfterSave未为文章触发
我正在开发一个带有onContentAfterSave事件的Joomla插件,用于在保存新文章后发送电子邮件 保存新菜单项或新类别时会触发该事件。 但不适用于新文章 乔姆拉!3.7.5Php Joomla:onContentAfterSave未为文章触发,php,plugins,joomla,joomla3.0,joomla-extensions,Php,Plugins,Joomla,Joomla3.0,Joomla Extensions,我正在开发一个带有onContentAfterSave事件的Joomla插件,用于在保存新文章后发送电子邮件 保存新菜单项或新类别时会触发该事件。 但不适用于新文章 乔姆拉!3.7.5 公共函数onContentAfterSave($context、$article、$isNew){ $link=JRoute::(ContentHelperRoute::getArticleRoute($article->id,$article->catid)); $mailer=JFactory::getMai
公共函数onContentAfterSave($context、$article、$isNew){
$link=JRoute::(ContentHelperRoute::getArticleRoute($article->id,$article->catid));
$mailer=JFactory::getMailer();
$config=JFactory::getConfig();
$sender=数组(
$config->get('mailfrom'),
$config->get('fromname')
);
$mailer->setSender($sender);
$user=JFactory::getUser();
$recipient=$user->email;
$recipient=数组($recipient);
$mailer->addRecipient($recipient);
$body='你好'
.“联合国新运动”;
$mailer->isHtml(true);
$mailer->Encoding='base64';
$mailer->setSubject('Nouveau article-BBN Times');
$mailer->setBody($body);
$send=$mailer->send();
如果($send!==true){
回显“发送电子邮件时出错:”;
}否则{
回显“已发送邮件”;
}
返回true;
}
onContentAfterSave由Joomla核心触发,而不是由扩展的模型触发,这意味着它应该由任何内容保存触发
我可以想到两个原因,为什么在您的案例中没有触发:
- 构造函数中有一个条件检查扩展类型,并且只允许某些扩展使用该事件(或插件中的其他地方)
- 上面的代码中有一个错误
- 构造函数中有一个条件检查扩展类型,并且只允许某些扩展使用该事件(或插件中的其他地方)
- 上面的代码中有一个错误
public function onContentAfterSave($context, $article, $isNew){
$link = JRoute::_(ContentHelperRoute::getArticleRoute( $article->id, $article->catid ));
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'mailfrom' ),
$config->get( 'fromname' )
);
$mailer->setSender($sender);
$user = JFactory::getUser();
$recipient = $user->email;
$recipient = array($recipient);
$mailer->addRecipient($recipient);
$body = '<p>Bonjour</p>'
.'Un nouveau <a href="'.$link.'">article</a> a été ajouté.';
$mailer->isHtml(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('Nouveau article - BBN Times');
$mailer->setBody($body);
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ';
} else {
echo 'Mail sent';
}
return true;
}