获取Joomla 2.5中的作者姓名

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取Joomla 2.5中的作者姓名相关的知识,希望对你有一定的参考价值。

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

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

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

你可以这样试试

//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;

希望这会帮助你。

以上是关于获取Joomla 2.5中的作者姓名的主要内容,如果未能解决你的问题,请参考以下文章

Joomla 2.5 从外部脚本获取用户数据

joomla 2.5中的require_once如何

如何在 joomla 2.5 的组件中加载模块

如何使用自定义插件将值插入 Joomla 2.5 DB

Joomla! 2.5 生成的URL中的组件菜单类型参数

PHP 中的 Joomla 独立脚本 - 握手