Magic methods in ThinkPHP query brief _ PHP Tutorial

Source: Internet
Author: User
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...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.