namespace app\index\controller;
use app\index\model\Teacher as TeacherModel;
use think\Request;
use app\index\model\Grade;
class Teacher extends Base
{
//教师列表
public function teacherList()
{ //获取所有教师表teacher数据
$teacher = TeacherModel::all();
//获取记录数量
$count = TeacherModel::count();
//遍历teacher表
foreach ($teacher as $value){
$data = [
'id' => $value->id, //主键
'name' => $value->name, //姓名
'degree' => $value->degree, //学历
'school' => $value->school, //毕业学校
'mobile' => $value->mobile, //手机号
'hiredate' => $value->hiredate, //入职时间
'status' => $value->status, //当前启用状态
//用关联方法grade属性方式访问grade表中数据
'grade' => isset($value->grade->name)? $value->grade->name : '<span style="color:red;">未分配</span>',
];
//每次关联查询结果,保存到数组 $teacher中
$teacherList[] = $data;
}
$this -> view -> assign('teacherList', $teacherList);
$this -> view -> assign('count', $count);
//设置当前页面的seo模板变量
$this->view->assign('title','编辑班级');
$this->view->assign('keywords','php.cn');
$this->view->assign('desc','PHP中文网ThinkPHP5开发实战课程');
return $this -> view -> fetch('teacher_list');
}