<body>
看到一份Thinkphp做微博开发的代码,但有些地方没有看懂:
一。控制器中的代码:
<code>/*</code>
-
首页视图
*/
-
function Index(){
<code> //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(); } </code>
二。视图中的代码:
<code> <!---ecms -ecms ====================普通微博样式====================--> <div class="weibo"> <!---ecms -ecms 头像--> <div class="face"> %20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20__ROOT__/Uploads/Face/{$v.face}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20__PUBLIC__/Images/noface.gif " width='50' height='50'/> </div> </code>
》》》》》
重点在这里:用户的头像$V.face 不知是来自哪里的。
weibo这个表中并没有face这一列,也没看到代码中去读取了另一个表中的信息,
它的weibo表结构是这样的:
头像信息可能是来自这个表:
但首页这个表中也只有face50%20%20face80%20%20face180%20而没有face这一列。
想请问它是怎样把不同表的数据放到同一个foreach中处理的?
原代码来自:https://github.com/milkbobo/Thinkphp3.2.3-weibo
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20
回复内容:
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20<body>
看到一份Thinkphp做微博开发的代码,但有些地方没有看懂:
一。控制器中的代码:
/*
-
首页视图
*/
-
function%20Index(){
%20%20%20%20%20%20%20//p(S('usermsg'.session('uid')));%20%20%20%20%20%20%20//replace_weibo('adsf');%20%20%20%20%20%20%20//p(C('FILTER'));%20%20%20%20%20%20%20$db=D('Weibo');%20%20%20%20%20%20%20%20%20%20%20%20%20%20//取得当前用户的ID与当前用户%20所有关注好友的ID%20%20%20%20%20%20%20%20%20%20%20%20%20%20$uid%20=%20array(session('uid'));//????%20%20%20%20%20%20%20$where=array('fans'=>session('uid'));%20%20%20%20%20%20%20%20%20%20%20%20%20%20if%20(isset($_GET['gid'])){%20%20%20%20%20%20%20%20%20%20%20$gid%20=%20I('gid','','intval');%20%20%20%20%20%20%20%20%20%20%20$where['gid']=$gid;%20%20%20%20%20%20%20%20%20%20%20$uid%20=%20'';%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20$result%2本文来源gao@daima#com搞(%代@#码@网&搞gaodaima代码0=M('follow')->where($where)->field('follow')->select();%20%20%20%20%20%20%20if($result){%20%20%20%20%20%20%20%20%20%20%20foreach%20($result%20as%20$v){%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20$uid[]%20=%20$v['follow'];%20%20%20%20%20%20%20%20%20%20%20}%20%20%20%20%20%20%20}%20%20%20%20%20%20%20%20%20%20%20%20%20%20//组合WHERE条件,条件为当前用户自身的ID与当前用户所关注好友的ID%20%20%20%20%20%20%20$where%20=%20array('uid'=>array('IN',$uid));//where条件可以是二维数组吗?%20%20%20%20%20%20%20%20%20%20%20%20%20%20//统计数据总条数,用于分页%20%20%20%20%20%20%20$count%20%20=%20$db->where($where)->count();//%20查询满足要求的%20总记录数%20%20%20%20%20%20%20%20%20$Page%20%20%20%20%20%20%20=%20new%20\Think\Page($count,20);//%20实例化分页类%20传入总记录数和每页显示的记录数(20)%20%20%20%20%20%20%20//%20进行分页数据查询%20注意limit方法的参数要使用Page类的属性%20%20%20%20%20%20%20$limit=$Page->firstRow.','.$Page->listRows;%20%20%20%20%20%20%20$Page->setConfig('theme',"共%20%TOTAL_ROW%%20条记录%20%FIRST%%20%UP_PAGE%%20%NOW_PAGE%%20/%20%TOTAL_PAGE%%20%DOWN_PAGE%%20%END%%20");%20%20%20%20%20%20%20$Page->setConfig('prev','上一页');%20%20%20%20%20%20%20$Page->setConfig('next','下一页');%20%20%20%20%20%20%20%20%20%20%20%20%20%20//读取所有微博%20%20%20%20%20%20%20$result=%20$db->getAll($where,$limit);//getAll()方法是驱动拓展里的%20%20%20%20%20%20%20//p($result);%20%20%20%20%20%20%20$this->page=%20$Page->show();//%20分页显示输出%20%20%20%20%20%20%20$this%20->%20weibo%20=%20$result;%20%20%20%20%20%20%20$this->display();%20%20%20%20%20%20%20%20%20%20}%20%20%20
二。视图中的代码:
%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20__ROOT__/Uploads/Face/{$v.face}%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20__PUBLIC__/Images/noface.gif " width='50' height='50'/>
》》》》》
重点在这里:用户的头像$V.face 不知是来自哪里的。
weibo这个表中并没有face这一列,也没看到代码中去读取了另一个表中的信息,
它的weibo表结构是这样的:
头像信息可能是来自这个表:
但首页这个表中也只有face50 face80 face180 而没有face这一列。
想请问它是怎样把不同表的数据放到同一个foreach中处理的?
原代码来自:https://github.com/milkbobo/Thinkphp3.2.3-weibo
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 ),