我有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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。