public function indexAction() { $response = new ApiResponse(); if ($this->request->isGet()) { $limit = $this->request->get('limit'); $page = $this->request->get('page'); $questions_id = $this->request->get('questions_id'); $answers = Answers::find(array("questions_id = '{$questions_id}'", "order" => "created_at DESC")); $paginator = new PaginatorModel(array("data" => $answers, "limit" => $limit, "page" => $page)); $page = $paginator->getPaginate(); // $response->setResponse( $page->items, count( $answers ) ); $res = []; foreach ($page->items as $item) { $user = Users::findFirstById($item->users_id); $res[] = array('id' => $item->id, 'content' => $item->content, 'photo' => $item->photo, 'questions_id' => $item->questions_id, 'upvotes' => $item->upvotes, 'downvotes' => $item->downvotes, 'created_at' => $item->created_at, 'users_id' => $item->users_id, 'avatar' => $user->avatar, 'username' => $user->username, 'email' => $user->email); } $response->setResponse($res, count($answers)); return $response; } else { $response->setResponseError('Wrong HTTP Method'); } return $response; }