當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Student::findBySql方法代碼示例

本文整理匯總了PHP中app\models\Student::findBySql方法的典型用法代碼示例。如果您正苦於以下問題:PHP Student::findBySql方法的具體用法?PHP Student::findBySql怎麽用?PHP Student::findBySql使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\models\Student的用法示例。


在下文中一共展示了Student::findBySql方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: actionFilter2

 public function actionFilter2()
 {
     $teachers = [];
     $students = [];
     $teachers = Teacher::findBySql("\n            select t.name, t.id from (\n                select st2.teacher_id st2, st3.teacher_id st3, count(st3.student_id) cnt from teacher_student st2\n                    left join teacher_student st3 on st3.student_id = st2.student_id and st2.teacher_id != st3.teacher_id\n                    where st3.teacher_id is not null group by st3.teacher_id, st2.teacher_id\n                    ) res \n                    left join teacher t on t.id=st2\n                    left join teacher t2 on t2.id=st3\n                    order by cnt DESC limit 2\n        ")->all();
     if (count($teachers) == 2) {
         $students = Student::findBySql("\n                select * from teacher_student st\n                left join student t on t.id = st.student_id \n                left join teacher_student st2 on st2.teacher_id = :teacher1 and st2.student_id = st.student_id\n                where st.teacher_id = :teacher2 and st2.teacher_id is not null\n            ", [':teacher1' => $teachers[0]->id, ':teacher2' => $teachers[1]->id])->all();
     }
     return $this->render('filter2', ['teachers' => $teachers, 'students' => $students]);
 }
開發者ID:ustkirill,項目名稱:testwork,代碼行數:10,代碼來源:TeacherController.php

示例2: beforeSave

 public function beforeSave($insert)
 {
     // hash password on before saving the record:
     if ($this->isNewRecord) {
         // get student id
         $id = $this->usr_type_id;
         $sql = 'SELECT * FROM student where st_id=' . $id;
         $stdnt = Student::findBySql($sql)->one();
         $this->usr_id = $stdnt->st_disp_id;
         $this->usr_pass = $this->hashPassword($this->usr_pass);
     }
     $this->usr_is_teacher = 0;
     $this->usr_is_admin = 0;
     $this->usr_is_su = 0;
     return parent::beforeSave($insert);
 }
開發者ID:AtaBashir,項目名稱:ams,代碼行數:16,代碼來源:UserStudent.php


注:本文中的app\models\Student::findBySql方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。