I found the error myself. The code is this:
JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
$model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request'=>true));
$appParams = JFactory::getApplication()->getParams();
$model->setState('params', $appParams);
$item =& $model->getItem($id);
The error was:
Fatal error: __clone method called on non-object in /var/www/site/joomla/components/com_content/models/article.php on line 170
Looking at the source code of class ContentModelArticle
(in components/com_content/models/application.php
) I noticed that the function getItem()
try to access the variable $params
of the state object. That variable is not previously initialized.
$registry = new JRegistry;
$registry->loadString($data->attribs);
$data->params = clone $this->getState('params'); // 'params' was not previously initialized! The call to clone will fail if you don't provide your own initialization.
$data->params->merge($registry);
The code above gets the article’s private attributes and then tries to override the global attributes.
Before the call to $model->getItem($id)
I supplied the global article attributes to the state object with the lines:
$appParams = JFactory::getApplication()->getParams();
$model->setState('params', $appParams);
Now it works.