I’m writing a Joomla 2.5.3 module. I’m trying to get an article from a JModel.
JModel::addIncludePath(JPATH_SITE.'/components/com_content/models', 'ContentModel');
$model =& JModel::getInstance('Article', 'ContentModel', array('ignore_request' => true));
$item =& $model->getItem((int) $id);
The result is:
Fatal error: __clone method called on non-object in /var/www/site/joomla/components/com_content/models/article.php on line 170
Does anyone know why?
EDIT:
Line 170 of /var/www/site/joomla/component/com_content/models/article.php is
$data->params = clone $this->getState('params');
If I do var_dump($tihs->getState('params')) I get NULL.
I found the error myself. The code is this:
The error was:
Looking at the source code of class
ContentModelArticle(incomponents/com_content/models/application.php) I noticed that the functiongetItem()try to access the variable$paramsof the state object. That variable is not previously initialized.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:Now it works.