/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Productos::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, 'precio' => $this->precio, 'categoria' => $this->categoria, 'activa' => $this->activa]); $query->andFilterWhere(['like', 'nombre', $this->nombre])->andFilterWhere(['like', 'descripcion_corta', $this->descripcion_corta])->andFilterWhere(['like', 'descripcion_larga', $this->descripcion_larga])->andFilterWhere(['like', 'tipo', $this->tipo])->andFilterWhere(['like', 'condiciones', $this->condiciones])->andFilterWhere(['like', 'ubicacion', $this->ubicacion]); return $dataProvider; }
public function actionActivacion() { $request = Yii::$app->request; $producto = Productos::find()->where(['id' => $request->get('id')])->one(); if ($producto->activa == 0) { $producto->activa = 1; $producto->update(); } else { $producto->activa = 0; $producto->update(); } return $this->redirect(['view', 'id' => $producto->id]); }
/** * Lists all Productos models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Productos::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
public function actionSearch() { $this->layout = "frontoffice"; $parametro = Yii::$app->request->post('nombre'); $lista = Productos::find()->where(['like', 'nombre', $parametro])->orWhere(['like', 'descripcion_corta', $parametro])->andWhere(['activa' => true])->all(); return $this->render('search', ["model" => $lista]); }