0

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

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

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

1 回答 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;

希望这会帮助你。

于 2013-06-06T12:38:30.917 回答