看到一份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(); }
二。視圖中的代碼:
__ROOT__/Uploads/Face/{$v.face} __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
回複內容:
看到一份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(); }
二。視圖中的代碼:
__ROOT__/Uploads/Face/{$v.face} __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 ),