我想知道如何獲得用戶名。我想要做的是這樣顯示的:
<a href="{$mybb->settings['bburl']}/usercp.php?action=profile">Username here</a>
我嘗試這樣做:
{$mybb->user['name']}'
但是不成功,我似乎無法找到在谷歌任何東西。
獲取用戶名 - MyBB
感謝您的幫助!
我想知道如何獲得用戶名。我想要做的是這樣顯示的:
<a href="{$mybb->settings['bburl']}/usercp.php?action=profile">Username here</a>
我嘗試這樣做:
{$mybb->user['name']}'
但是不成功,我似乎無法找到在谷歌任何東西。
獲取用戶名 - MyBB
感謝您的幫助!
我不是那麼有經驗的MyBB,但經過一些研究後,我發現了幾種不同的方法。
$user = get_user($uid);
echo $user['username'];
或
global $db;
$qry = $db->query("SELECT uid FROM ".TABLE_PREFIX."users WHERE username = '".$usernamevar."'");
而且你可以將所有類似這樣的,我想。
<?php
define("IN_MYBB", 1);
require ('global.php'); // be sure that u r running this php-code in the same
// directory of global.php, or else change the path.
if($mybb->user['uid'] > 0)
{
$uid = $mybb->user['uid'];
$user = get_user($uid);
$name = $user['username'];
}
// custom else here: in case of not logged-in user
?>
<a href="{$mybb->settings['bburl']}/usercp.php?action=profile"><?echo $name?></a>
試着把這個放到你的模板中。
{$mybb->user['username']}
不需要使用PHP作爲已存在的變量。
我現在就試試吧!一秒鐘... – 2012-04-08 10:29:26
代碼是否工作? – Harry 2012-04-08 10:46:15
我實際上得到了這個工作: '{$ mybb-> user ['username']}' 哈哈,我是4封信。儘管感謝您的幫助! – 2012-04-08 10:49:50