I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places: I. Code in the Controller: {code...} homepage view * functionIndex () {code...} 2. Code in the View: {code...} "focuses on this: the user's profile picture $ V. face does not know...
I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places:
I. Code in the controller:
/*
Function Index (){
// P (S ('usermsg '. session ('uid'); // replace_weibo ('adsf '); // p (C ('filter'); $ db = D ('weibo '); // obtain the ID of the current user and the ID of all the followers of the current user $ 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'] ;}// combine WHERE conditions, the condition is that the ID of the current user and the ID of the friend that the current user is interested IN $ where = array ('uid' => array ('in', $ uid )); // can the where condition be a two-dimensional array? // The total number of statistical data records, used for paging $ count = $ db-> where ($ where)-> count (); // query the total number of records meeting the requirements $ Page = new \ Think \ Page ($ count, 20 ); // instantiate the total number of incoming records and the number of records displayed on each page (20) // perform paging data query. Note that the parameters of the limit Method must use the property $ limit = $ Page-> firstRow of the Page class. ','. $ Page-> listRows; $ Page-> setConfig ('Theme ', "% TOTAL_ROW % records % FIRST % UP_PAGE % NOW_PAGE %/% TOTAL_PAGE % DOWN_PAGE % END %"); $ Page-> setConfig ('prev ', 'previous page'); $ Page-> setConfig ('Next', 'next page'); // read all Weibo Posts $ result = $ db-> getAll ($ where, $ limit); // The getAll () method is the // p ($ result) in the drive expansion; $ this-> page = $ Page-> show (); // display the output by PAGE $ this-> weibo = $ result; $ this-> display ();}
II. Code in the View:
/Uploads/Face/{$ v. face} /Public/Images/noface.gif"Width = '50' height = '50'/>
"
The focus is on this: the user's profile picture $ V. face does not know where it comes from.
The weibo table does not have the face column, and the Code does not read the information in another table,
Its weibo table structure is as follows:
The profile picture information may be from this table:
However, in the homepage table, only face50 face80 face180 is used, but not the face column.
How does one put data from different tables in the same foreach for processing?
Source code from: https://github.com/milkbobo/Thinkphp3.2.3-weibo
Reply content:
I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places:
I. Code in the controller:
/*
Function Index (){
// P (S ('usermsg '. session ('uid'); // replace_weibo ('adsf '); // p (C ('filter'); $ db = D ('weibo '); // obtain the ID of the current user and the ID of all the followers of the current user $ 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'] ;}// combine WHERE conditions, the condition is that the ID of the current user and the ID of the friend that the current user is interested IN $ where = array ('uid' => array ('in', $ uid )); // can the where condition be a two-dimensional array? // The total number of statistical data records, used for paging $ count = $ db-> where ($ where)-> count (); // query the total number of records meeting the requirements $ Page = new \ Think \ Page ($ count, 20 ); // instantiate the total number of incoming records and the number of records displayed on each page (20) // perform paging data query. Note that the parameters of the limit Method must use the property $ limit = $ Page-> firstRow of the Page class. ','. $ Page-> listRows; $ Page-> setConfig ('Theme ', "% TOTAL_ROW % records % FIRST % UP_PAGE % NOW_PAGE %/% TOTAL_PAGE % DOWN_PAGE % END %"); $ Page-> setConfig ('prev ', 'previous page'); $ Page-> setConfig ('Next', 'next page'); // read all Weibo Posts $ result = $ db-> getAll ($ where, $ limit); // The getAll () method is the // p ($ result) in the drive expansion; $ this-> page = $ Page-> show (); // display the output by PAGE $ this-> weibo = $ result; $ this-> display ();}
II. Code in the View:
/Uploads/Face/{$ v. face} /Public/Images/noface.gif"Width = '50' height = '50'/>
"
The focus is on this: the user's profile picture $ V. face does not know where it comes from.
The weibo table does not have the face column, and the Code does not read the information in another table,
Its weibo table structure is as follows:
The profile picture information may be from this table:
However, in the homepage table, only face50 face80 face180 is used, but not the face column.
How does one put data from different tables in the same foreach for processing?
Source code from: 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 ),