Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.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
Php Joomla:onContentAfterSave未为文章触发_Php_Plugins_Joomla_Joomla3.0_Joomla Extensions - Fatal编程技术网

Php Joomla:onContentAfterSave未为文章触发

Php 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事件的Joomla插件,用于在保存新文章后发送电子邮件

保存新菜单项或新类别时会触发该事件。 但不适用于新文章

乔姆拉!3.7.5

公共函数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核心触发,而不是由扩展的模型触发,这意味着它应该由任何内容保存触发

我可以想到两个原因,为什么在您的案例中没有触发:

  • 构造函数中有一个条件检查扩展类型,并且只允许某些扩展使用该事件(或插件中的其他地方)
  • 上面的代码中有一个错误

onContentAfterSave由Joomla核心触发,而不是由扩展的模型触发,这意味着它应该由任何内容保存触发

我可以想到两个原因,为什么在您的案例中没有触发:

  • 构造函数中有一个条件检查扩展类型,并且只允许某些扩展使用该事件(或插件中的其他地方)
  • 上面的代码中有一个错误

我的插件适用于所有类型(菜单、类别…),但不适用于文章类型。实际上,如果($isNew and in_array($context,array('com_content.article','com_content.form'))我的插件适用于所有类型(菜单,类别…),但不适用于文章类型,我就使用这个条件。实际上,如果($isNew和in_array($context,array('com_content.article','com_content.form')),我会使用这个条件
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;
}