1

我在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,但是当点击分页时,它显示相同的数据。是什么导致了这个错误?

4

1 回答 1

0

该参数$params代表您的标准条件。当您单击下一页时,这些条件将发送到您的搜索功能。因此,在您的代码中,您必须将这些实际加载$params 到您的搜索模型中。即:

    ....     
   $dataProvider = new ActiveDataProvider([
        'query' => $query,
    ]);

    $this->load($params);
   ....

您还必须将其删除$tech=array(22,24,25,29)并将其放在您的控制器中,即:

$yourDataProvider = $yourSearchModel->search([$yourSearchModel->formName() => ['tbl_assignment.id' => $tech]])
于 2017-11-07T08:05:20.283 回答