全站在模板中判断用户信息的时候是有缓存的,这有时候就有一定的误差了,比如判断关注不关注 判断积分多少 判断金额多少等等
login_user get_user $userdb 等等都是有一定的缓存。我们就自己做一个没有缓存的fun就可以了。
那么我们在application\common\fun 下面新建一个 User.php 把代码复制进去就可以了。
php和模板中的使用方法看注释即可,有获取单字段的 有全部字段的
<?php namespace app\common\fun; class User{ /** * 获取用后的单个字段信息 * @param string $type 获取的用户字段 默认为用户名 * fun('user@user','wx_attention') 获取当前登录的 * fun('user@user','wx_attention',2) 获取用户2的 * @return \app\common\model\NULL|mixed */ public static function user($type='username',$uid=0){ if(empty($uid)){ $uid=login_user('uid'); } $info=\app\common\model\User::get_info($uid,'uid'); return $info[$type]; } /** * 获取用户的全部资料 包含密码等敏感信息 * fun('user@userinfo') 获取当前登录用户的 * fun('user@userinfo',2) 获取用户为2的 * @return \app\common\model\NULL[]|\app\common\model\unknown|array */ public static function userinfo($uid=0){ if(empty($uid)){ $uid=login_user('uid'); } $info=\app\common\model\User::get_info($uid,'uid'); return $info; } }