6

我正在写一个 Joomla!我需要在其中显示当前文章标题的模块。

我在stackoverflow的某个地方找到了这段代码:

<?php
$option = JRequest::getCmd('option');
$view = JRequest::getCmd('view');
$ids = explode(':',JRequest::getString('id'));
$article_id = $ids[0];
$article =& JTable::getInstance("content");
$article->load($article_id);
echo $article->get("title");
?>

虽然它有效,但它使用了已弃用的 JRequest 类,因为它来自 Joomla 1.7 而我使用的是 3.2.2。有人可以告诉我如何重写它以使 Joomla 3.2 有效吗?

4

1 回答 1

15

您可以使用以下使用最新编码标准的代码:

$input = JFactory::getApplication()->input;
$id = $input->getInt('id'); //get the article ID
$article = JTable::getInstance('content');
$article->load($id);

echo $article->get('title'); // display the article title

希望这可以帮助

于 2014-02-27T13:42:21.293 回答