简体   繁体   中英

Access Joomla 3.2 article title from the module displayed alongside

I'm writing a Joomla! module in which I need to display current article title.

I've got this code found somewhere here on a 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. Can someone tell me how to rewrite it to be valid with 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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