我希望通过在 Joomla 模板中传递文章 ID 来获取文章文本。
简单来说,只要你在post/get中附带文章ID并使用"id"作为其编号即可:
$articleId = JRequest::getInt('id');
$db =& JFactory::getDBO();
$sql = "SELECT fulltext FROM #__content WHERE id = ".intval($articleId);
$db->setQuery($sql);
$fullArticle = $db->loadResult();
if(!strlen(trim($fullArticle))) $fullArticle = "Article is empty ";
编辑:从任何地方获取文章ID的方法:
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
在Joomla 2.5中(根据文档,3也可以),插件中通过文章ID获取文章文本:
$article =& JTable::getInstance("content");
$article->load($id);
$content = '<h3>'. $article->get("title").'</h3>';
$content .= $article->get("introtext"); // introtext and/or fulltext
From inside own component:
$app = JFactory::getApplication();
$params = $app->getParams();
$param = $params->get('terms_article_id');
From other component:
$params = JComponentHelper::getParams('com_mycom');
$id = $params->get('terms_article_id');
Get Module Parameter from template's php file:
$module = JModuleHelper::getModule('mod_mymodule');
$params = new JRegistry($module->params); // or $mymoduleParams if few used
$id = (int) $headLineParams['count'];
尝试这个技巧:
$article = JControllerLegacy::getInstance('Content')->getModel('Article')->getItem($articleId);
echo $article->introtext;
Joomla有从SQL表中获取内容的默认脚本。
这里是文章 (#__content)
获取文章ID:
$articleId = (JRequest::getVar('option')==='com_content' && JRequest::getVar('view')==='article')? JRequest::getInt('id') : 0;
$table_plan = & JTable::getInstance('Content', 'JTable');
$table_plan_return = $table_plan->load(array('id'=>$articleId));
echo "<pre>";print_r($table_plan->introtext);echo "</pre>";