A brief introduction to the Magic method in thinkphp query _php tutorial

Source: Internet
Author: User
When we use thinkphp development, we sometimes use GetByID (' 1 ') method to quickly get a message content, this method is more useful than using where ("ID =1")->find (), and query efficiency is faster than find.

Many people, when they first approached this method, did not pay much attention to its internal implementation mechanism, only to think that the information was obtained by ID, and that is not the case.
For example, some systems have Getbytitle ("Nihao"), Getbymoney (' 1000 ') methods, which are similar to the GetByID (' 1 ') just mentioned, and also implement the same functional principle as GetByID (' 1 ').
In fact, like this GetByID ($id), Getbytitle ($title), Getbyusername ($username), and so on, the "getby+ field" method has a proper noun called "magic Method", The field behind it can be any field in the data table, and the result can only be the first data that is queried , and this method is very efficient and well remembered.
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 the Hump method to name , should be written so Getbyusername ($name) on it!

http://www.bkjia.com/PHPjc/824803.html www.bkjia.com true http://www.bkjia.com/PHPjc/824803.html techarticle when we use thinkphp development, we sometimes use the GetByID (' 1 ') method to quickly get a message content, this method is more useful than using the WHERE ("ID =1")-find (), at the same time ...

  • 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.