0

在我的扩展中,我从content表中检索到如下文章:

.......
.......
$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"');
.......
.......

在这里,我可以检索attribs正在检索的每篇文章的数据。

有没有一种简单的方法可以从全局设置中检索文章参数(Joomla 中是否有某种静态函数?)还是我需要paramsextensions表中手动检索?

4

1 回答 1

3

您可能希望使用JComponentHelper类来获取组件的参数。

<?php

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

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

要获取文章,我不会像您那样自己编写查询,而是使用相关的 JModel(Joomla 3 中的 JModelLegacy)实例。

看起来像:

<?php

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

不知道该特定代码是否有效,但您当然可以在 Google 上对此进行一些研究。精神在那里:使用 Joomla 提供的类,而不是直接从数据库中提取东西。您将获得可维护性和代码质量。

于 2014-02-25T07:39:25.177 回答