Home  >  Article  >  Backend Development  >  How to use model in thinkphp

How to use model in thinkphp

不言
不言Original
2018-07-06 10:02:537044browse

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>

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

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’]   -----班级(一个老师对应学生一个)
 
}

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!

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