Access Joomla 3.2 article title from the module displayed alongside
Asked Answered
S

1

6

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 ?

Scherzando answered 27/2, 2014 at 13:33 Comment(0)
G
15

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

Gujarat answered 27/2, 2014 at 13:42 Comment(1)
I wouldn't dare to forget :) Just had to wait for few minutes before stackoverflow would allow me toScherzando

© 2022 - 2024 — McMap. All rights reserved.