我在modelsearch中有以下代码用于gridview数据显示。
public function search($params )
{
$tech=array(22,24,25,29);
$query=(new \yii\db\Query())-> select(['tbl_ticket.*',
'tbl_assignment.ticket_id',
'tbl_assignment.tech_id',
'tbl_assignment.date_time',
'tbl_techs.f_name',
'tbl_techs.loc',
'tbl_techs.attachment',
'tbl_techs.dep',
'tbl_techs.sec']);
$query->from('tbl_ticket');
$query->join('LEFT JOIN', 'tbl_assignment', 'tbl_assignment.ticket_id = tbl_ticket.id');
$query->join('LEFT JOIN', 'tbl_techs', 'tbl_techs.id = tbl_assignment.tech_id');
$query->where(['tbl_assignment.id' => $tech]);
$para = isset($_POST['Email']) ? $_POST['Email'] : $_GET['email'];
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 5,
'params'=>array('email' => $para)
],
]);
$query->andWhere(['tbl_ticket.hd_user_email' => $para]);
if (! ($this->load($params ) && $this->validate())) {
return $dataProvider;
}
$query->andFilterWhere(array(
'id' => $this->id,
'ticket_id' => $this->ticket_id,
'tech_id' => $this->tech_id,
'date_time' => $this->date_time,
));
return $dataProvider;
}
它显示了gridview,但是当单击分页时,它会显示相同的数据。 是什么导致了这个错误?
答案 0 :(得分:0)
参数$params
代表您的条件条件。
当您单击下一页时,这些条件将发送到您的搜索功能。因此,在您的代码中,您必须将这些$params
实际加载到搜索模型.ie:
....
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
....
您还必须删除$tech=array(22,24,25,29)
并将其保存在您的控制器中,即:
$yourDataProvider = $yourSearchModel->search([$yourSearchModel->formName() => ['tbl_assignment.id' => $tech]])