users = $users; $this->clubs = $clubs; parent::__construct(); } function renderIndex(): void { $query = $this->queryParam("query") ?? ""; $type = $this->queryParam("type") ?? "users"; $page = (int) ($this->queryParam("p") ?? 1); $this->willExecuteWriteAction(); if($query != "") $this->assertUserLoggedIn(); // https://youtu.be/pSAWM5YuXx8 $repos = [ "groups" => "clubs", "users" => "users" ]; $repo = $repos[$type] or $this->throwError(400, "Bad Request", "Invalid search entity $type."); $results = $this->{$repo}->find($query); $iterator = $results->page($page); $count = $results->size(); $this->template->iterator = iterator_to_array($iterator); $this->template->count = $count; $this->template->type = $type; $this->template->page = $page; } }