2

I have follow code for after save:

public function onContentAfterSave ($context, $article, $isNew)
{
$article = JModelLegacy::getInstance('Article', 'ContentModel')->getItem(); 
....
}

It works fine if I save an article.
But it will execute too if I save other things like a Weblink, so there comes the error measage:

Call to a member function getItem() on boolean

Now I'am look for a rule to check that the code only execute by save an article like

 public function onContentAfterSave ($context, $article, $isNew)
    {
    if (IS_A_ARTCLE) {  ... }
    }
2

You use the $context variable for that. So you have to start your function like this:

public function onContentAfterSave ($context, $article, $isNew)
{
  if ($context == "com_content.article") {
      // Your code for articles here
  }
}
  • Fantastc, THATS it. nexttime I will RTFM. 1000 Thanks – Lovntola Jan 18 at 9:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.