Home > Article > Backend Development > How to use model in thinkphp
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]['student'] -----学生(一个班级对应学生多个) $list[$key]['teacher'] ------老师(一个班级对应学生一个) } --------------------------------------------------------------------------------------------- $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!