typecho访问个人主页author无用户信息相关问题

author.php文件一般很少用到,先放出问题所在

访问用户a的个人主页,如果a发布过文章,则页面主页页面可以正常获取到a的邮箱,头像等相关信息

但是如果a没有发布过文章,则页面不能获取到相关个人信息,原因是获取并不到相关的用户id,但是浏览器的地址是带有用户的uid的,所以通过浏览器的地址,获取到用户uid,通过uid查询,反馈到页面中显示出用户相关信息

<?php 
if(empty($this->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;
}

显示代码:

<?php $this->user->mail(); ?>
文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/82
0 评论
2.6k

发表评论

!