How TP5 displays different fields on the interface

不言
Release: 2023-04-03 08:42:02
Original
2203 people have browsed it

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']);
Copy after login

$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!

Related labels:
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
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!