两个列表查看同一页Yii2

时间:2018-08-06 12:07:44

标签: php yii2

我试图用Yii2在同一页面中放置两个列表视图,但是每当我将页面更改为一个时,第二个更改也是如此。有什么建议么?我搜索了所有地方,但没有发现任何类似的问题,尽管我认为这是非常基本的。有帮助吗?

1 个答案:

答案 0 :(得分:-1)

  In controller you may pass two data provider for the two list views this may help 
  you to solve this

  public function actionView($id)
    {
        $model = $this->findModel($id);

        $reportsToUserDataProvider = new ActiveDataProvider([
            'query' => $model->parent()
        ]);


        $reporteeDataProvider = new ActiveDataProvider([
            'query' => $model->children(),
            'pagination' => false,
        ]);
            Yii::$app->session->setFlash('alert', [
                'options' => ['class' => 'alert-success'],
                'body' => 'Your Reportees has been updated successfully'
            ]);
        }

        return $this->render('view', [
                'model' => $model,
                'reportsToUserDataProvider' => $reportsToUserDataProvider,
                'reporteeDataProvider' => $reporteeDataProvider,
]);
}