本文整理汇总了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);
}