我有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