看到一份Thinkphp做微博开发的代码,但有些地方没有看懂:
一。控制器中的代码:
/*
首页视图
*/
-
function Index(){
//p(S('usermsg'.session('uid'))); //replace_weibo('adsf'); //p(C('FILTER')); $db=D('Weibo'); //取得当前用户的ID与当前用户 所有关注好友的ID $uid = array(session('uid'));//???? $where=array('fans'=>session('uid')); if (isset($_GET['gid'])){ $gid = I('gid','','intval'); $where['gid']=$gid; $uid = ''; } $result =M('follow')->where($where)->field('follow')->select(); if($result){ foreach ($result as $v){ $uid[] = $v['follow']; } } //组合WHERE条件,条件为当前用户自身的ID与当前用户所关注好友的ID $where = array('uid'=>array('IN',$uid));//where条件可以是二维数组吗? //统计数据总条数,用于分页 $count = $db->where($where)->count();// 查询满足要求的 总记录数 $Page = new \Think\Page($count,20);// 实例化分页类 传入总记录数和每页显示的记录数(20) // 进行分页数据查询 注意limit方法的参数要使用Page类的属性 $limit=$Page->firstRow.','.$Page->listRows; $Page->setConfig('theme',"共 %TOTAL_ROW% 条记录 %FIRST% %UP_PAGE% %NOW_PAGE% / %TOTAL_PAGE% %DOWN_PAGE% %END% "); $Page->setConfig('prev','上一页'); $Page->setConfig('next','下一页'); //读取所有微博 $result= $db->getAll($where,$limit);//getAll()方法是驱动拓展里的 //p($result); $this->page= $Page->show();// 分页显示输出 $this -> weibo = $result; $this->display(); }
二。视图中的代码:
<foreach name='weibo' item='v'>
<if condition='!$v["isturn"]'>
<!--====================普通微博样式====================-->
<div class="weibo">
<!--头像-->
<div class="face">
<a href="{:U('/' . $v['uid'])}">
<img src="
<if condition='$v["face"]'>
__ROOT__/Uploads/Face/{$v.face}
<else/>
__PUBLIC__/Images/noface.gif
</if>" width='50' height='50'/>
</a>
</div>
》》》》》
重点在这里:用户的头像$V.face 不知是来自哪里的。
weibo这个表中并没有face这一列,也没看到代码中去读取了另一个表中的信息,
它的weibo表结构是这样的:
头像信息可能是来自这个表:
但首页这个表中也只有face50 face80 face180 而没有face这一列。
想请问它是怎样把不同表的数据放到同一个foreach中处理的?
Index/Home/Model/CommentModel.class.php
10 'id','content','time','wid',//'uid',
11 '_type'=>'LEFT'
12 ),
13 'userinfo'=>array(
14 'username','face50'=>'face','uid',
15 '_on'=>'comment.uid = userinfo.uid'
16 ),