author.php文件一般很少用到,先放出问题所在
访问用户a的个人主页,如果a发布过文章,则页面主页页面可以正常获取到a的邮箱,头像等相关信息
但是如果a没有发布过文章,则页面不能获取到相关个人信息,原因是获取并不到相关的用户id,但是浏览器的地址是带有用户的uid的,所以通过浏览器的地址,获取到用户uid,通过uid查询,反馈到页面中显示出用户相关信息
author->uid)){
$str=$_SERVER["REQUEST_URI"];
if(preg_match('/\d+/',$str,$arr)){
$id=$arr[0];
if ($this->user->hasLogin()&&$this->user->uid==$id){$lock=0;}else{$lock=1;}
$info=userok($id);
$this->user->uid=$id;
$this->user->screenName=$info['screenName'];
$this->user->mail=$info['mail'];
$this->user->group=$info['group'];
}
}
?>
判断用户uid是否存在,如果不存在,则获取浏览器的地址,读取uid,进行查询
function userok($id){
$db = Typecho_Db::get();
$userinfo=$db->fetchRow($db->select()->from ('table.users')->where ('table.users.uid=?',$id));
return $userinfo;
}
显示代码:
user->mail(); ?>
!
发表评论