unsplash = new UnsplashService(); parent::init(); } /** * Render the plugins main page and show the latest Unsplash images * @param $page int * @return Response */ public function actionIndex($page = 1): Response { $data = $this->unsplash->getLatest($page); return $this->renderTemplate('splashing-images/_index', [ 'data' => $data, ]); } /** * Redirect search form submit to correct results url * @throws \yii\web\BadRequestHttpException */ public function actionFind() { $query = Craft::$app->request->getRequiredBodyParam('query'); return $this->redirect(UrlHelper::cpUrl('splashing-images/search/1', ['search' => $query])); } /** * Handles searching & returning images from Unsplash * @param $query string * @param $page int * @return bool|Response */ public function actionSearch(int $page) { $query = $this->request->getRequiredQueryParam('search'); if (!$query) { return false; } $data = $this->unsplash->search($query, $page); return $this->renderTemplate('splashing-images/_search',['data' => $data]); } }