Beispiel #1
0
 /**
  * Find profession categories with professions links
  * @param array $config
  */
 public function __construct($config = [])
 {
     $this->categorias = Categorias::find()->with(['articulos' => function ($query) {
         $query->andWhere(['in', 'estado', [Articulos::NUEVO, Articulos::USADO, Articulos::OFERTA, Articulos::RESERVADO]])->orderBy(['idarticulo' => SORT_DESC]);
     }])->activas()->all();
     parent::__construct($config);
 }
 public function prepareDataProvider()
 {
     $params = \Yii::$app->request->queryParams;
     //print_r($params);die();
     $model = new $this->modelClass();
     // I'm using yii\base\Model::getAttributes() here
     // In a real app I'd rather properly assign
     // $model->scenario then use $model->safeAttributes() instead
     $modelAttr = $model->attributes;
     // this will hold filtering attrs pairs ( 'name' => 'value' )
     $search = [];
     if (!empty($params)) {
         foreach ($params as $key => $value) {
             // In case if you don't want to allow wired requests
             // holding 'objects', 'arrays' or 'resources'
             if (!is_scalar($key) or !is_scalar($value)) {
                 throw new BadRequestHttpException('Bad Request');
             }
             // if the attr name is not a reserved Keyword like 'q' or 'sort' and
             // is matching one of models attributes then we need it to filter results
             if (!in_array(strtolower($key), $this->reservedParams) && ArrayHelper::keyExists($key, $modelAttr, false)) {
                 $search[$key] = $value;
             }
         }
     }
     // you may implement and return your 'ActiveDataProvider' instance here.
     // in my case I prefer using the built in Search Class generated by Gii which is already
     // performing validation and using 'like' whenever the attr is expecting a 'string' value.
     $searchByAttr['ProductSearch'] = $search;
     $lat = isset($params['lat']) ? $params['lat'] : 18.509111;
     $lon = isset($params['lon']) ? $params['lon'] : -69.8468487;
     $model = new Categorias();
     $searchModel = $model->find()->all();
     return $searchModel;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categorias::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(['idcategoria' => $this->idcategoria, 'padre' => $this->padre]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre]);
     return $dataProvider;
 }
 /**
  * Finds the Usuarios model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Categorias the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($slug)
 {
     if (($model = Categorias::find()->where(['slug' => $slug])->one()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #5
0
 /**
  * Listado categorias
  * @return array
  */
 public function listadoCategoriasFull()
 {
     return Categorias::find()->publicas()->limite(14)->aleatorio()->all();
 }