Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 720
zorza Avatar asked Feb 27 '14 13:02

zorza


1 Answers

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

like image 167
Lodder Avatar answered Oct 20 '22 07:10

Lodder