public function actionIndex() { $model = new Record(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect('site/list'); } else { $data = $model->departmentInfo(); //if max count boys, we doesnt display department $department = []; foreach ($data as $key => $item) { if ($item['boys_count'] != $item['max_boys']) { $department[$key] = $item['name']; } } return $this->render('index', ['model' => $model, 'data' => $data, 'department' => $department]); } }