mneri
mneri

Reputation: 2217

How to Get Global Article Parameters in Joomla?

I'm programming a module in Joomla! 2.5. The module displays an article at a given position. I need article attributes (i.e. show_title, link_title ecc.) With this code I get article's specific attributes:

$db =& JFactory::getDBO();
$query = 'SELECT * FROM #__content WHERE id='.$id.' AND state=1';
$db->setQuery($query);
$item = $db->loadObject();
$attribs = json_decode($item->attribs, true);

If i var_dump the $attribs variable I get:

array(26) {
  ["show_title"]=>
  string(0) ""
  ["link_titles"]=>
  string(0) ""

  [...]

}

The variable $attribs represents the article's specific attributes. When an element is set to "" means "use the global configuration".

I can get the global configuration with this query:

SELECT params from #__extensions where extension_id=22;

Where 22 is the id of the com_component extension. Then I can merge the results here with the results for the specific article.

BUT is there an easy way to achieve this? Does Joomla! have a specific class in the framework for this?

Upvotes: 1

Views: 7513

Answers (1)

Craig
Craig

Reputation: 9330

I would start with loading the model for articles:

// Get an instance of the generic articles model
$model = JModel::getInstance('Article',
                             'ContentModel',
                             array('ignore_request' => true));

The get the specific article...

$model->getItem($id)

To get a components global params I believe you can use:

$params = &JComponentHelper::getParams( 'COMPONENT_NAME' );

In your case you would need something like:

jimport('joomla.application.component.helper'); // load component helper first
$params = JComponentHelper::getParams('com_content');

I would suggest you look at the code of the article modules that ship with Joomla! 2.5.x as they do a lot of similar things to what you're trying to create. You can also have a read of this article, it's a bit dated but I think it still mostly holds true (except for jparams being replaced by jforms).

Upvotes: 3

Related Questions