I have an issue with a cli php script that I'm trying to execute. I want to add an article with custom fields.

The part where I add articles is working well, but when I add the code to load the article I just stored and set its custom fields values, there is the following error:

Call to undefined method AddArticle::getTemplate(): JLIB_APPLICATION_ERROR_INVALID_CONTROLLER

The error seems to be related to the following line:

$article_joom = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($article['id']);

I've tried to load the ContentLoader class because someone said it would help, but it didn't really change anything.

From what I've seen, I may not be able to use the JController on a cli script, but I haven't found another way to load articles.

  • What was the line # and file that called AddArtcile::getTemplate() ?
    – Irata
    Aug 8, 2020 at 1:06
  • @Irata In my script I created a class AddArticle extended to JApplicationCli. But never did I use any getTemplate method and the error doesn't give the name of a file or a line # . But I also get the following warning : Use of undefined constant JPATH_COMPONENT - assumed 'JPATH_COMPONENT' (this will throw an Error in a future version of PHP) in C:\xampp\htdocs\V2\libraries\src\MVC\Controller\BaseController.php on line 232 Aug 11, 2020 at 10:59

1 Answer 1


Start by updating to the latest version of Joomla - 3.9.20 - if you're able to first.

A number of changes regarding JControllerLegacy were made in Joomla 3.8 (see https://github.com/joomla/joomla-cms/pull/13683) and so that is certainly worth investigating first.

Next take a look at this post which relates to calling JController from CLI Call Controller's Publish-Method from CLI or Helper

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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