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

WBOY
Release: 2016-08-18 09:15:44
Original
954 people have browsed it

1. Yii2 ActiveDataProvider has its own paging function. When using ActiveDataProvider in the list, there is no need to find out the results of the query. Usually for convenience, it is directly queried in the columns of the GridView to convert the id into a name. However, this approach is When checking debug, the same statement will be executed multiple times, which affects efficiency. Is this wrong according to the usage specifications of Yii2?
2. If you don’t query the columns of GridView to convert the ID into a name, how should you deal with it? Is it a good idea to use a multi-table association query to convert the id into a name before passing it to the GridView?

Reply content:

1. Yii2 ActiveDataProvider has its own paging function. When using ActiveDataProvider in the list, there is no need to find out the results of the query. Usually for convenience, it is directly queried in the columns of the GridView to convert the id into a name. However, this method is not suitable for When checking debug, the same statement will be executed multiple times, which affects efficiency. Is this wrong according to the usage specifications of Yii2?
2. If you don’t query the columns of the GridView to convert the ID into a name, how should you deal with it? Is it a good idea to use a multi-table association query to convert the id into a name before passing it to the GridView?

Combination of two methods:

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

    <code>$query->with(['store'])->where(['name' => $something]);
    </code>
    Copy after login

In this way, the contents of the store table will be included in the result set, and there is no need to query repeatedly. This should be a standard practice;

  1. It is really unavoidable. Enable memcache and save the results in memory in advance, which can also effectively reduce database pressure.

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!