获取Joomla 2.5中的作者姓名

问题描述 投票:0回答:1

如何获取Joomla 2.5中当前文章的作者姓名?

我尝试使用这个代码,但它给了我号码;

$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_author = $article->created_by;
echo $article_author;
joomla alias author
1个回答
2
投票

你可以这样试试

//this method of getting requested variable is deprecated 
$id = JRequest::getInt('id');

//use JFactory::getApplication()->input instead of JRequest::getInt()

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

//get user id which create the article
$created_user_id = $article->created_by;

//fetch user
$user = JFactory::getUser($created_user_id);
$article_author = $user->name;
echo $article_author;

希望这会帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.