Hi,
I have a list view populated using cgridview. Outside the grid view i have a seach form where various parameters can be entered. On clicking submit form, i should be able to get the searched result using the values provided.
I have succeeded in filtering the results using single variable. But when multiple values are to be searched i cannot make it to work.
Controller :
$this -> layout = 'main';
if(isset($_GET['search_key'])){
$search = $_GET['search_key'];
$model->firstName = $search;
$model->lastName = $search;
$model->email = $search;
}
$this -> render('staffmanagement', array('model' => $model));
Model :
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('title',$this->title,true);
$criteria->compare('firstName',$this->firstName,true,'OR');
$criteria->compare('lastName',$this->lastName,true,'OR');
$criteria->compare('email',$this->email,true,"OR");
$criteria->compare('userType',$this->userType,true);
$criteria->compare('mob_organisationId',$this->mob_organisationId,true);
$criteria->compare('createdDate',$this->createdDate,true);
$criteria->compare('modifiedDate',$this->modifiedDate,true);
$criteria->compare('active',$this->active,true);
$criteria->addCondition('firstName',$this->firstName,'OR');
$criteria->addCondition('lastName',$this->lastName,'OR');
$criteria->addCondition('email',$this->email,'OR');
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
View :
<?php
echo CHtml::beginForm('', 'get');
echo(CHtml::textField('search_key', '',array('class' => 'search_txt', 'placeholder' =>'Search')));
echo CHtml::endForm();
?>
When i remove all the addCondition() in model
$criteria->addCondition('firstName',$this->firstName,'OR');
$criteria->addCondition('lastName',$this->lastName,'OR');
$criteria->addCondition('email',$this->email,'OR');
as well as remove two values from controller
$model->lastName = $lastName;
$model->email = $email;
the search works perfectly for a single value (firstName).
How can i add other two parameters also and keep the form working ?