Beispiel #1
0
 /**
  * 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;
 }
 /**
  * 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]);
 }