A brief description of the magic method in ThinkPHP query. When we use thinkphp for development, we sometimes use the getById (1) method to quickly obtain a piece of information. this method is better than where (id1)-find () it is much easier to use. when we use thinkphp for development, the getById ('1') method is sometimes used to quickly obtain a piece of information, this method is much easier to use than where ("id = 1")-> find (), and the query efficiency is faster than find.
Many people did not pay much attention to its internal implementation mechanism when they first came into contact with this method. they only thought it was to obtain information through id, but this was not the case.
For example, some systems have methods such as getByTitle ("nihao") and getByMoney ('000000'). These methods are similar to the getById ('1') mentioned earlier, at the same time, the function principle is the same as getById ('1.
In fact, similar to the getById ($ id), getByTitle ($ title), getByUserName ($ username), and so on, the "getBy + field" method has a proprietary term called "magic method ",The field following it can be any field in the data table, and the returned result can only be the first data queried.The query efficiency of this method is very high and it is easy to remember.
Sometimes our fields are not connected, such as user_name. do we write (getByUser_name ($ name) like this? The answer is No. thinkphp does not support this method. WeUse the hump method to name, It should be written as this getByUserName ($ name!
Extract ('1') this method quickly obtains the content of a piece of information. this method is much easier to use than where ("id = 1")-find (), and...