/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Rubrics::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionRubric() { Yii::$app->response->format = Response::FORMAT_JSON; $rubrics = ['output' => [], 'selected' => '']; if ($depdrop_parents = Yii::$app->request->post('depdrop_parents')) { $rubrics_arr = Rubrics::find()->select('id,name')->where(['category_id' => $depdrop_parents[0]])->asArray()->all(); $rubrics['output'] = $rubrics_arr; } return $rubrics; }
/** * Finds the Rubrics model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Rubrics the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Rubrics::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Updates an existing Goods model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post())) { $model->imageFile = UploadedFile::getInstance($model, 'imageFile'); $oldname = $model->image; $filename = $model->imageFile ? $model->imageFile->baseName . '.' . $model->imageFile->extension : $model->image; if ($model->imageFile && $oldname != $filename) { $model->image = $filename; } if ($model->save()) { if ($oldname != $filename) { $model->uploadImage(); } return $this->redirect(['view', 'id' => $model->id]); } } $rubrics = ArrayHelper::map(Rubrics::find()->asArray()->indexBy('id')->all(), 'id', 'name'); return $this->render('update', ['model' => $model, 'rubrics' => $rubrics]); }
/** * @return \yii\db\ActiveQuery */ public function getRubric() { return $this->hasOne(Rubrics::className(), ['id' => 'rubric_id']); }
/** * @return \yii\db\ActiveQuery */ public function getRubrics() { return $this->hasMany(Rubrics::className(), ['category_id' => 'id']); }