ThinkPHP PHP framework study notes

  • 2020-03-31 16:46:44
  • OfStack

Spent more than two hours looking at the ThinkPHP framework, not wanting to get too deep into all of its advanced theories. Simply want to know how to use, can quickly build a website. So there is a choice to see, two hours later or a fog. So decided to change the learning strategy, on the official forum to see other people wrote the civil course, as expected more than the official easy to understand. (link: http://bbs.thinkphp.cn/forumdisplay.php? Fid =6) (official forum)

ThinkPHP has a number of functions that combine SQL in a patchwork of arguments, as follows: $list = $test - > The.findall (' $fields, 'id desc' $p - > FirstRow. ', '. $p - > ListRows); Although this patchwork approach simplifies our SQL statements, it also requires us to remember many functional methods. I don't want to memorize too many of these things, but sometimes it is easier to just write a full SQL. I wonder if ThinkPHP directly write SQL after the execution of the select query function method? Later, I learned that model.class.php has a method called public function query($SQL) that can meet my requirements! When you do pagination, you just skip the query method and use the findall method to implement pagination.

You've seen examples and tutorials that work with a single table, but there are many cases where we use multi-table federation. What should you do if you want to join a multi-table query? ThinkPHP has taken this issue into account and has been very thoughtful in helping us arrange associated queries and operations. I hate all this trouble! In fact, flexible use of the framework within some basic function methods, you can achieve the correlation query and correlation operations. There's no need to memorize a lot of stuff.

Data paging is a feature that is often used, and TP is relatively easy to do. Find a tutorial on the Internet ((link: http://bbs.phpchina.com/thread-52813-1-1.html)), thought this tutorial to write a reference TP paging program should be very simple. Did not expect or quite a lot of trouble!

(1)         It started with an encounter Fatal error :     Class 'Think' not found in... . Error prompt, in the web to find a general knowledge is missing an extended class library. Later in the official website to download the corresponding documents.

(2)         The extended class library has no error, but it still cannot display the desired result correctly! Check the "page Trace information", it turns out that SQL has a problem, SELECT COUNT() AS tp_count FROM 'think_demo' LIMIT 1, the analysis results in this tutorial sentence $count ; =   $test - > The count(" ", "" id") code has a problem. =   $test - > Count ('id') finally sees the hyperlink from the previous page to the next. Better believe than have no book!

(3)         Use the tutorial's $list  =   $test - > The.findall (" ', $fields, 'id  Desc ', $p - > FirstRow. ', '. $p - > ListRows); I never got the result I wanted with this code, and I don't want to get into the details of how the various parameters of the findall method are used. So $list = $test-> Query ("select $fields from think_demo order by id desc limit $p-> FirstRow, $p - > ListRows "). Run again, this time finally paging out!


Related articles: