Пример #1
0
 public function actionStudentlist($id)
 {
     // "Response content must not be an array."
     /*$students = \app\models\Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->all();
       return $students;
        */
     // "Response content must be a string or an object implementing __toString()"
     $DataProvider = new ActiveDataProvider(['query' => Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->all()]);
     // When use this and return $Model instead of $DataProvider
     // http://stackoverflow.com/questions/27746984/criteria-active-data-provider-in-yii-2
     $Model = $DataProvider->getModels();
     return $Model;
 }
 public static function actionStudentlist($id)
 {
     // "Response content must not be an array."
     /*$students = \app\models\Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->all();
       return $students;
        */
     $query = Studentmodule::find()->where(['Module_id' => $id]);
     // Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->asArray()->all(),
     $StudentDataProvider = new ActiveDataProvider(['query' => $query]);
     // $students = $StudentDataProvider->getModels();
     echo GridView::widget(['id' => 'studentsGrid_' + uniqid(), 'dataProvider' => $StudentDataProvider, 'columns' => ['student.firstName', 'student.studentNum', ['class' => 'yii\\grid\\CheckboxColumn', 'checkboxOptions' => ['onclick' => '$.post(\'index.php?r=attendance/createattendance&id=\'+ $(this).val() ' . '+ \'&date="\' + $(\'#attendance-date\').val() + \'"\');']]]]);
     //var_dump($students);
     //        // "Response content must be a string or an object implementing __toString()"
     //        $DataProvider = new ActiveDataProvider([
     //            'query' => Studentmodule::find()->where(['Module_id' => $id])->orderBy('id')->asArray()->all(),
     //        ]);
     //
     //        // When use this and return $Model instead of $DataProvider
     //        // http://stackoverflow.com/questions/27746984/criteria-active-data-provider-in-yii-2
     //        $Model= $DataProvider->getModels();
     //
     //        return $Model;
 }