0

In my extension, I've retrieved articles from the content table like this:

.......
.......
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('id, catid, title, introtext, attribs);
$query->from('#__content');
$query->where('catid="'.$cid.'"');
$query->where('state="1"');
.......
.......

Here I can retrieve attribs data for each article being retrieved.

Is there an easy way to retrieve article params from the global settings (is there some sort of static function in Joomla?) or do I need to manually retrieve the params from the extensions table?

user1448031
  • 2,172
  • 11
  • 44
  • 89

1 Answers1

3

You might want to use the JComponentHelper class to get the params of the component.

<?php

jimport( 'joomla.application.component.helper' );

$com_content_params = JComponentHelper::getParams('com_content');

To get the articles I wouldn't write the query myself as you do, but use the relevant JModel (JModelLegacy in Joomla 3) instance instead.

Something that would look like:

<?php

$model = JModel::getInstance('Articles', 'ContentModel');
$model->setState('filter.category_id', (int)$cid);
$articles = $model->getList();

Don't know if that specific code will work, but you certainly can do some research on Google about that. The spirit is there: use the classes provided by Joomla instead of pulling stuff directly from the DB. You'll gain in maintainability and code quality.

Bgi
  • 2,513
  • 13
  • 12
  • Thanks for pointing me to the right direction. I'm now redoing my extension by using `JModelLegacy` and it seems to work fine. But I am unable to figure out how the ordering works. I tried something like this: `$model->setState('list.ordering', 'a.publish_up');` but it does not seem to have any effect on the output. Is there something else I have to do in order to get the ordering working? – user1448031 Feb 25 '14 at 12:44
  • ``publish_up`` is set to 0 by default, try ``created_date``. – Bgi Feb 25 '14 at 16:12
  • No I tried few different options such as `title, hits, etc` but none of them seem to work. `print_r($model->getItems());` outputs an array like this: `Array ( [0] => stdClass Object ( [id] => 12 [title] => Test [alias] => test [introtext] => testtest [checked_out] => 0 [checked_out_time] => 0000-00-00 00:00:00 [catid] => 2 [created] => 2014-02-02 00:00:01.................` Still can't figure out why the ordering does not work. Any idea? – user1448031 Feb 25 '14 at 22:26