/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Characteristics::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Exemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function loadChars()
 {
     return Characteristics::find()->where(['product_id' => $this->id])->all();
 }
Exemplo n.º 3
0
 public function actionDelete($id)
 {
     if (!Yii::$app->user->can('product/delete')) {
         Yii::$app->session->setFlash('error', 'Нет доступа!');
         return $this->redirect('/');
     }
     $images = Images::find()->where(['product_id' => $id])->all();
     $char = Characteristics::find()->where(['product_id' => $id])->all();
     foreach ($char as $c) {
         $c->delete();
     }
     foreach ($images as $image) {
         if (file_exists(Yii::getAlias('@webroot/uploads/image_product/original/' . $image->url_image)) == true) {
             unlink(Yii::getAlias('@webroot/uploads/image_product/original/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/xm/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/sm/' . $image->url_image));
             unlink(Yii::getAlias('@webroot/uploads/image_product/lm/' . $image->url_image));
         }
         $image->delete();
     }
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }