When we use thinkphp to develop the system, we sometimes use the GetByID (' 1 ') method to get the content of a piece of information quickly, rather than using the WHERE ("ID =1")->find (); It's much better and faster than find.
At the beginning of contact with this method, did not pay much attention to its internal is how to achieve, feel like its name, through the ID to get information, slowly accepted this method, until today, I see a video, it appears inside Getbytitle ("Nihao"), Getbymoney (' 1000 '), these very similar methods, which do not explain their meaning. I feel very use is also very surprised, so I try to find their implementation of the function of the program, through the online search and look at the development of their own documents, finally understand what is the same thing, how to use this method flexibly.
Like this GetByID ($id), Getbytitle ($title), Getbyusername ($username), the method of getby+ field has a proper noun called the Magic method, and the field behind it can be any field in the data table. The return result can only be the first data of the query, this method of query efficiency is very high, very good to remember.
Sometimes our field is not connected, for example: user_name such as the field, we do not write this way (Getbyuser_name ($name))? The answer is no, thinkphp does not support such a method, we need to use hump hair to name, should be written such getbyusername ($name).
reprint:qiyuefeng.blog.51cto.com/7322546/1220769
Thinkphp Magic Method