Home>Article>Backend Development> How TP5 displays different fields on the interface

How TP5 displays different fields on the interface

不言
不言 Original
2018-07-17 18:03:53 2218browse

This article mainly introduces how TP5 displays different fields on the interface, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Environment ThinkPHP5 PHP7.0.10

We usually hide some fields and apply them to different interfaces

First change the database configuration file and change the data set return type to collection

The query of our interface below is processed the same whether it is find() or select()

$Group = $Group->hidden(['name']);

$Group is the data queried by mode. This line of code means to hide the name.

Of course we can also use the visible() method to define which fields are only displayed, so that I can add some fields that do not need to be displayed to the $hidden array in the Model, and the selection of other fields is in the controller. Continue

Let’s look at an example

This is all the information read

Let’s hide the name field

Or only display the name

In this way, we can flexibly define the information displayed by the interface to the client, in the Model You can also choose not to hide, and display client information in the controller.

Suppose I hide this field in the Model, and then choose to display only this field in the controller, it will also be displayed. on the client side.

It can be seen that the hiding of the Model can also be changed by the controller

Related recommendations:

php5 connects to the image field image display in the mssql2005 database table

The above is the detailed content of How TP5 displays different fields on the interface. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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