A
A
Alexander2015-05-15 13:05:56
Yii
Alexander, 2015-05-15 13:05:56

How to solve the task?

Hello toaster!
I have 3 fields for data search And two types of data search, the first is an input where the user can enter the name of the district himself, or select it in an existing select. All plows the data outputs. But there is such a bug when the user selects a city but does not select a district and then presses search, then all districts of all cities will be displayed, and there are a lot of them. Must have chosen the city crawled out all the districts of this city. I was prompted if an empty field then in criteria set a non-existing parameter
thumb.png

public function search()
  {
    // @todo Please modify the following code to remove attributes that should not be searched.
    $criteria=new CDbCriteria;
    $criteria->compare('id',$this->id);
    $criteria->compare('district_id',$this->district_id);
    $criteria->compare('name_ru',$this->name_ru,true);
    $criteria->compare('name_en',$this->name_en,true);
    $criteria->compare('address_ru',$this->address_ru,true);
    $criteria->compare('address_en',$this->address_en,true);
    $criteria->compare('sort',$this->sort);
    $criteria->compare('active',$this->active);
    if(intval(Yii::app()->request->getParam('RefMahala',['district_id'=>null])['district_id']) <= null){  // проверка если пустой option в теге select 
      $criteria->compare('active', 4);   // то я задаю не существующий параметр что вернет : нет результатов 
    };
    return new CActiveDataProvider($this, array(
      'criteria'=>$criteria,
    ));
  }

Verification works great! but if the user wants to enter the name of the district itself and then clicks search, then two $_POST will be sent - and 1 is an input 2 -select with an empty option, if an empty option is sent, this check will work
if(intval(Yii::app() ->request->getParam('RefMahala',['district_id'=>null])['district_id']) <= null){
$criteria->compare('active', 4);
};
and will return no results.
It seems that I described the problem in more detail, can you help me solve it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2015-05-15
@kentuck1213

solved :D
if($_POST['RefMahala']['name_en'] && $_POST['RefMahala']['district_id'] == null){
$criteria->compare('active',$this->active );
} else if (!$_POST['RefMahala']['name_ru'] && $_POST['RefMahala']['district_id'] == null){
$criteria->compare('active', 4);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question