这篇文章主要介绍了关于thinkphp中model的使用方法,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
首先:有三个数据表

现在用命令行建立它们的模型
<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>

立即学习“PHP免费学习笔记(深入)”;
<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 index/Teacher<br/></span></code>
php think make:model index/Student
用法:
$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’] -----班级(一个老师对应学生一个)
}以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
以上就是thinkphp中model的使用方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号