I recently started to build a custom keyword search using Yii 1.1.x
The search works 100%. But as soon as I sort the columns and use pagination in the admin view the search gets lost and all results are shown. So with otherwords it’s not filtering so that only the search results show. Somehow it resets it.
In my controller my code looks as follows
$builder=Messages::model()->getCommandBuilder();
//Table1 Columns
$columns1=array('0'=>'id','1'=>'to','2'=>'from','3'=>'message','4'=>'error_code','5'=>'date_send');
//Table 2 Columns
$columns2=array('0'=>'username');
//building the Keywords
$keywords = explode(' ',$_REQUEST['search']);
$count=0;
foreach($keywords as $key){
$kw[$count]=$key;
++$count;
}
$keywords=$kw;
$condition1=$builder->createSearchCondition(Messages::model()->tableName(),$columns1,$keywords,$prefix='t.');
$condition2=$builder->createSearchCondition(Users::model()->tableName(),$columns2,$keywords);
$condition = substr($condition1,0,-1) . " OR ".substr($condition2,1);
$condition = str_replace('AND','OR',$condition);
$dataProvider=new CActiveDataProvider('Messages', array(
'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
'criteria'=>array(
'with'=>'users',
'together'=>true,
'joinType'=>'LEFT JOIN',
'condition'=>$condition,
),
'sort'=>$sort,
));
$this->render('admin',array(
'dataProvider'=>$dataProvider,'keywords'=>implode(' ',$keywords),'sort'=>$sort
));
and my view looks like this
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
array(
'name'=>'user_id',
'value'=>'CHtml::encode(Users::model()->getReseller($data->user_id))',
'visible'=>Yii::app()->user->checkAccess('poweradministrator')
),
'to',
'from',
'message',
/*
'date_send',
*/
array(
'name'=>'error_code',
'value'=>'CHtml::encode($data->status($data->error_code))',
),
array(
'class'=>'CButtonColumn',
'template'=>'{view} {delete}',
),
),
));
I really do not know what do do anymore since I’m terribly lost, any help will be hihsly appreciated