/** * Displays a single Attr model. * @param integer $id * @return mixed */ public function actionView($id) { $searchModel = new AttrValSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams, $id); $model = $this->findModel($id); $valmodel = new AttrVal(); if ($valmodel->load(Yii::$app->request->post())) { if ($valmodel->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('view', ['model' => $model, 'list' => $model->getVals(), 'dataProvider' => $dataProvider, 'valmodel' => $valmodel]); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $id = null) { $query = AttrVal::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->andFilterWhere(['attr_id' => $id]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'cover' => $this->cover, 'price' => $this->price, 'status' => $this->status]); $query->andFilterWhere(['like', 'val', $this->val]); return $dataProvider; }
/** * Finds the AttrVal model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return AttrVal the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AttrVal::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }