本文整理匯總了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]);
}
示例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);
}