为什么列表渲染不出来啊
尾生
尾生 2019-03-19 14:47:10
0
0
1182

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');
    }


尾生
尾生

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!