Example #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;
 }
Example #2
0
 public static function listData($model, $keyName, $valueName)
 {
     $data = [];
     $provider = new ActiveDataProvider(['query' => $model::find(), 'pagination' => false]);
     foreach ($provider->getModels() as $model) {
         $data[$model->{$keyName}] = $model->{$valueName};
     }
     return $data;
 }