php yii结果集合并,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

标签:cgridview,search,yii,criteria,php

来源: https://codeday.me/bug/20191029/1959630.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值