Answer the question
In order to leave comments, you need to log in
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
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,
));
}
Answer the question
In order to leave comments, you need to log in
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 questionAsk a Question
731 491 924 answers to any question