How to use model in thinkphp

不言
Release: 2023-04-02 16:16:01
Original
7090 people have browsed it

This article mainly introduces how to use models in thinkphp. It has certain reference value. Now I share it with you. Friends in need can refer to it.

First of all: there are three data tables

Now use the command line to build their models

<code style="background: #f9fafa; margin: 0px; padding: 0px; border: currentColor; line-height: inherit; font-family: Consolas, "Liberation Mono", Menlo, Courier, monospace; font-size: 13.56px; display: inline; white-space: pre; max-width: 100%"><span class="bash">php think make:model admin/Class<br/></span></code>
Copy after login

<code   style="max-width:90%"><span class="bash">php think make:model index/Teacher<br/></span></code>
Copy after login
php think make:model index/Student
Copy after login

Usage:

$list = Classs::all();
  foreach($list as $key=>$value){
    $list[$key][&#39;student&#39;]   -----学生(一个班级对应学生多个)
    $list[$key][&#39;teacher&#39;]  ------老师(一个班级对应学生一个)
}
---------------------------------------------------------------------------------------------
   $list = TeacherDb::all();
  foreach($list as $key=>$value){
    $list[$key][‘class’]   -----班级(一个老师对应学生一个)
 
}
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

PHP uses Azure Storage Blob to upload files

TP5 determines the mobile terminal and PC terminal

The above is the detailed content of How to use model in thinkphp. 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
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!