Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Autos::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, 'fecha_registro' => $this->fecha_registro, 'id_estado' => $this->id_estado]);
     $query->andFilterWhere(['like', 'marca', $this->marca]);
     /*
     ->andFilterWhere(['like', 'modelo', $this->modelo])
     ->andFilterWhere(['like', 'ano', $this->ano])
     ->andFilterWhere(['like', 'color', $this->color])
     ->andFilterWhere(['like', 'no_motor', $this->no_motor])
     ->andFilterWhere(['like', 'matricula_auto', $this->matricula_auto])
     ->andFilterWhere(['like', 'no_chassis', $this->no_chassis])
     ->andFilterWhere(['like', 'observaciones', $this->observaciones])
     ->andFilterWhere(['like', 'kilometraje', $this->kilometraje])
     ->andFilterWhere(['like', 'no_chapa', $this->no_chapa]);
     */
     $sort = SORT_DESC;
     if (!empty($params['AutosSearch']['sort'])) {
         $sort = $params['AutosSearch']['sort'];
     }
     $query->orderBy = ['fecha_registro' => $sort];
     $precioRange = '1-999999';
     if (!empty($params['AutosSearch']['precioRange'])) {
         $precioRange = explode('-', $params['AutosSearch']['precioRange']);
         $precioRange[0] = intval(trim($precioRange[0]));
         $precioRange[1] = intval(trim($precioRange[1]));
         $query->andWhere("precio >= " . $precioRange[0]);
         $query->andWhere("precio <= " . $precioRange[1]);
     }
     //Fn::PrintVar($query, 'query');
     //exit;
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdAuto()
 {
     return $this->hasOne(Autos::className(), ['id' => 'id_auto']);
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAutos()
 {
     return $this->hasMany(Autos::className(), ['id_estado' => 'id']);
 }
Esempio n. 4
0
 /**
  * Finds the Autos model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Autos the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Autos::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }