/**
  * 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;
 }
 /**
  * Finds the Characteristics model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Characteristics the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Characteristics::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function loadChars()
 {
     return Characteristics::find()->where(['product_id' => $this->id])->all();
 }
Exemple #4
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']);
 }