public function result($id) { $datastore = new Survey(); $survey = $datastore->get(['id' => $id])->First(); $this->viewData['survey'] = $survey; $datastore = new SurveyChoice(); $choices = $datastore->get(['surveyId' => $id])->ToArray(); $this->viewData['choices'] = $choices; $voteCount = 0; foreach ($choices as $choice) { $voteCount += $choice->getCount(); } $this->viewData['voteCount'] = $voteCount; return $this->view("Result"); }