Should Yii2 query in columns of the GridView to convert the id into a name?

Source: Internet
Author: User
1. the paging function provided by Yii2ActiveDataProvider does not need to query the result when ActiveDataProvider is used in the list, in normal times, the id is converted into a name directly in columns of the GridView for convenience, but this method is used to view the debug... 1. the page feature of Yii2 ActiveDataProvider does not need to query the result when ActiveDataProvider is used in the list, in normal times, the id is converted into a name directly in columns of the GridView for convenience. However, when you view debug, the same statement is executed multiple times, which affects the efficiency. In terms of Yii2 usage specifications, isn't this true?
2. what should I do if I do not convert the id into a name in columns of the GridView? How can I convert an id to a name using a multi-table join query before uploading it to the GridView?

Reply content:

1. the page feature of Yii2 ActiveDataProvider does not need to query the result when ActiveDataProvider is used in the list, in normal times, the id is converted into a name directly in columns of the GridView for convenience. However, when you view debug, the same statement is executed multiple times, which affects the efficiency. In terms of Yii2 usage specifications, isn't this true?
2. what should I do if I do not convert the id into a name in columns of the GridView? How can I convert an id to a name using a multi-table join query before uploading it to the GridView?

The two methods are combined:

  1. When constructing ActiveDataProvider, add with (), for example:

    $query->with(['store'])->where(['name' => $something]);

In this way, the content of the store table is included in the result set without repeated queries. This should be a standard practice;

  1. If memcache is enabled and the results are saved in the memory in advance, the pressure on the database can be effectively reduced.

Related Article

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.