public function actionCategory($categoryId) { $category = ProductCategory::findOne($categoryId); if (empty($category)) { throw new NotFoundHttpException('The requested page does not exist.'); } if ($this->isAjax()) { $model = new Recipe(); $model->productCategoryId = $categoryId; return $this->renderPartial('@app/views/partials/_category-ingredients-dropdown-list', ['model' => $model, 'form' => ActiveForm::begin()]); } else { $params = Yii::$app->request->queryParams; $params['categoryId'] = $categoryId; $searchModel = new ProductRepository(); $dataProvider = $searchModel->search($params); return $this->render(['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'categoryName' => $category->name]); } }
/** * Finds the ProductCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProductCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProductCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }