PHP-合并两个CActiveDataProvider并在yii中的CGridview中显示结果

我有2个型号:

 $model = new Profileinformation('internetConection');
 $modeliner = new Profileinformation('inerConection');

我在yii中的2 CGridView中显示了那些如何在CGridView中显示

模型:

 public function internetConection() {
        // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->condition = 'serviceId=:serviceId';
    $criteria->params = array(':serviceId' => '1');
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileinformationId) AS internetConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileinformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}

public function inerConection() {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->addInCondition('serviceId', array(2, 3, 4, 5));
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileinformationId) AS inerConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileinformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}

我现在正在使用2 CgridView,但是如果我可以在表中显示它非常好.
每个结果搜索都有一个新字段:inerConectionCount和internetConectionCount.

InternetConectionCount表

inernetConectionCount表
 

我要它:

 $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'profile-information-grid1',
        'dataProvider' => $dataprovider
            'columns' => array(
            array(
                'header' => '',
                'value' => '$this->grid->dataProvider->pagination->offset + $row+1', //  row is zero based
            ),

             array(
                'name' => 'Profileinformation.user.organization',
                'value' => 'CHtml::encode($data->user->organization)',

            ),

            array(
                'name' => 'Profileinformation.user.scope',
                'value' => 'CHtml::encode($data->user->scope->name)',
                'filter' => Scope::model()->options,
            ),
            array(
                'name' => 'id',
                'value' => 'CHtml::encode($data->id)',
            ),

          'inerConectionCount',



        ),
    ));

解决方法:

您可以合并来自两个提供程序的数据,但是必须禁用分页,否则每个提供程序中的记录限制为10条记录

$model = new Profileinformation('internetConection');
$modeliner = new Profileinformation('inerConection');

$data = CMap::mergeArray( // combine two data
    $model->search()->getData(),
    $modeliner ->search()->getData()
);

$provider = new CArrayDataProvider( $data ); // use CArrayDataProvider instead of CActiveDataProvider

相关文章

1、将Yii2.0advanced版中应用主体frontend或backend应用复制...
Yii2restfulAPI文档一、配置模块:1.Config/main.php:  2...
Yii在framework/i18n/data/%lang%.php文件中有很多翻译.这...
在Yii2中,官方的页面多语言解决方案有两个:方案1,使用Yii...
Yii2.0对数据库查询的一些简单的操作1234567891011121314151...
数据查询User::find()->all();此方法返回所有数据;User:...