场景
一个班级拥有多个学生,一个学生只能够属于某个班级,查询某个班级的信息及该班级的学生姓名列表。
数据模型
- think_student 学生表
id | student_name | class_id |
---|---|---|
1 | 柯南 | 2 |
2 | 元太 | 2 |
3 | 步美 | 2 |
4 | 小哀 | 2 |
5 | 光彦 | 2 |
- think_class 班级表
id | class_name |
---|---|
1 | 一年级A班 |
2 | 一年级B班 |
3 | 一年级C班 |
代码
- 创建 ClassModel.class.php 内容如下:
1 | <?php |
- 创建 StudentModel.class.php 内容如下:
1 | <?php |
- 创建 TestController.class.php 内容如下:
1 | <?php |
查询
1 | { |