如何在视图中访问activedataprovider

时间:2017-06-10 06:04:56

标签: view controller yii2

在我的控制器中我有这个actionView,它包含结果,如何将结果导入视图页面     $ this-> title = $ dataProvider-> vchr_name;这个得到错误。我如何在视图中访问数据提供者。请帮帮我。

public function actionView($id)
        {
            $query = new Query; 
            $dataProvider = new ActiveDataProvider([

                     'query'=> $query
                                ->select(['vchr_name','vchr_actual_hours','vchr_worked_hours','vchr_month', 'year'])
                                ->from('tbl_payroll')
                                ->join( 'INNER JOIN', 'tbl_employee', 'tbl_employee.pk_int_emp_id = tbl_payroll.fk_int_emp_id')
                                ->join('INNER JOIN', 'tbl_payroll_month', 'tbl_payroll_month.pk_int_payroll_month_id = tbl_payroll.fk_int_payroll_month')
                                ->join('INNER JOIN', 'tbl_payroll_year', 'tbl_payroll_year.pk_int_payroll_year_id = tbl_payroll.fk_int_payroll_year')
                                ->where(['pk_int_payroll_id'=> $id])
                                ->One(),
                                ]);
                return $this->render('view', [
                   'dataProvider' => $dataProvider,   
            ]);
         }   

1 个答案:

答案 0 :(得分:0)

您应该访问adataProvider的models属性

 $allModels = $dataProvider->models;

 $allModels = $dataProvider->getModels(); // for actual page

$ allModels包含一组模型,例如:用于访问第一个模型,你可以

echo $allModels[0]['my_attribute'];

例如:

echo $allModels[0]['vchr_name'];