In ContractorsController I have two functions - to get a list of users that have logged in and those that have not logged in. The resulting view gives me the correct data however I am unable to search the results.
In the ContractorsController I am getting data from a different model (User) - this is the function in Contractors Contoller:
public function actionLoginhistory() {
$model=new User('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['User'])) {
$model->attributes=$_GET['User'];
}
$this->render('loginlist', array(
'model'=>$model,
));
}
The View for this is as follows
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'striped bordered condensed',
'dataProvider' => $model->loginsearch(),
'filter'=>$model,
'ajaxUpdate'=>false,
'enablePagination'=>true,
'summaryText'=>'Displaying {start}-{end} of {count} results.',
'template' => "{summary}{items}{pager}",
'htmlOptions'=>array('style' => 'width:500px;margin-left: 130px;',),
'columns' => array(
array('name' => 'real_name', 'header'=> 'Trading Name','htmlOptions'=>array('width'=>'50%'),
'type'=>'raw',
'value' =>'CHtml::link($data->real_name, array("contractors/viewalldocuments","id"=>$data->username))',
),
array('name' => 'email', 'header' => 'Email','htmlOptions'=>array('width'=>'30%')),
array('name' => 'last_login', 'header' => 'Last Login', 'filter'=>false, 'htmlOptions'=>array('width'=>'20%'), 'value' => 'date("d-m-Y", strtotime($data->last_login))'),
))
);
I created a function in the User model which refers to the above dataProvider:
public function loginsearch()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('real_name',$this->real_name,true);
$criteria->compare('username',$this->username,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('last_login',$this->last_login,true);
$criteria->condition = 'last_login IS NOT NULL AND user_type_id=4';
return new CActiveDataProvider($this, array(
'pagination' => array(
'pageSize' => 80,
),
'criteria'=>$criteria,
));
}
I initially get the correct data in the view however when I try to search within the results I am simply returned the results I got from the initial query - the search does not narrow down the results - I am just returned all the results from the initial query. If I change the line in the view to
'dataProvider' => $model->search(),
The search function works - however what I want is DIFFERENT search functions for different views. The search function in the User model is
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('real_name',$this->real_name,true);
$criteria->compare('username',$this->username,true);
$criteria->compare('email',$this->email,true);
$criteria->compare('last_login',$this->last_login,true);
return new CActiveDataProvider($this, array(
'pagination' => array(
'pageSize' => 80,
),
'criteria'=>$criteria,
));
}
Is it possible to have different search functions in the model? Remember I am using a search function from the User model in the Contractors controller/Contractors views.