获取Joomla 2.5中的作者姓名

时间:2013-06-06 12:27:38

标签: joomla alias author

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

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

$id = JRequest::getInt('id');
$article =& JTable::getInstance('content');
$article->load($id);
$article_author = $article->created_by;
echo $article_author;

1 个答案:

答案 0 :(得分: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;

希望这会对你有所帮助。