简体   繁体   English

从旁边显示的模块访问Joomla 3.2文章标题

[英]Access Joomla 3.2 article title from the module displayed alongside

I'm writing a Joomla! 我正在写一个Joomla! module in which I need to display current article title. 我需要显示当前文章标题的模块。

I've got this code found somewhere here on a stackoverflow: 我已经在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");
?>

Although it works, it uses deprecated class JRequest, because it's from Joomla 1.7 and I use 3.2.2. 虽然它有效,但它使用了弃用的类JRequest,因为它来自Joomla 1.7而我使用的是3.2.2。 Can someone tell me how to rewrite it to be valid with Joomla 3.2 ? 有人能告诉我如何重写它以使Joomla 3.2有效吗?

You can use the following code which uses up to date coding standards: 您可以使用以下使用最新编码标准的代码:

$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

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM