如何在yii2中动态添加detailView中的行数

how to add number of rows in detailView dynamically in yii2

$dataProviderDetails = new ActiveDataProvider([

                 'query'=> $details
                            ->select(['pk_int_particular_id','vchr_particular_name','int_amount'])
                            ->from('tbl_payroll_details')
                            ->join( 'INNER JOIN', 'tbl_salary_particular', 'tbl_salary_particular.pk_int_particular_id = tbl_payroll_details.fk_salary_particular_id')
                            ->where(['fk_int_payroll_id'=> $id])
                            ->All(),
                            ]);


        $payroll = $dataProviderDetails->query;    
        return $this->render('view', [
               //'model' => $model, 
               'payroll' => $payroll  
        ]);

这个连接包含的结果集是

Array ( [0] => Array ( [pk_int_particular_id] => 1 [vchr_particular_name] => basicSalary [int_amount] => 10000 ) [1] => Array ( [pk_int_particular_id] => 2 [vchr_particular_name] => HRA [int_amount] => 200 ) [2] => Array ( [pk_int_particular_id] => 3 [vchr_particular_name] => PA [int_amount] => 500 ) [3] => Array ( [pk_int_particular_id] => 4 [vchr_particular_name] => professionaltax [int_amount] => 1000 ) )

我在 detailView 中打印了结果 $payroll[0][vchr_particular_name]

但我想知道如何使用数组索引在 detailView 中动态添加行数。可能吗?

如果您只需要总行数 select,您可以在查询中使用 count() 而不是全部

->select(['pk_int_particular_id', 'vchr_particular_name', 'int_amount'])
  ->from('tbl_payroll_details')
  ->join( 'INNER JOIN',  'tbl_salary_particular',  'tbl_salary_particular.pk_int_particular_id = tbl_payroll_details.fk_salary_particular_id')
  ->where(['fk_int_payroll_id'=> $id])
  ->count()

但请记住,在 activeDataProvider 中,这应该已经由对象本身计算并存储在 'totalCount' 属性 或者你可以使用 getTotalCount() 方法 activeDataProvider

 $dataProviderDetails->totalCount;
 $dataProviderDetails->getTotalCount();