将dataprovider更改为给定关系yii的模型

将dataprovider更改为给定关系yii的模型,yii,Yii,有两个表,百分比和存储。有一个关系,我可以从商店中获取百分比数据,例如$stores->percentageTable 我希望从百分比表中获取数据。我一直在通过一个循环来做这件事,但我不想再使用循环了。希望通过使用cactivedaptaprovider来解决问题 视图:我想要像顶部一样的东西。第二部分是我通常会做的 <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'commiss

有两个表,百分比和存储。有一个关系,我可以从商店中获取百分比数据,例如$stores->percentageTable

我希望从百分比表中获取数据。我一直在通过一个循环来做这件事,但我不想再使用循环了。希望通过使用
cactivedaptaprovider
来解决问题

视图:我想要像顶部一样的东西。第二部分是我通常会做的

  <?php $this->widget('zii.widgets.grid.CGridView', array(
        'id'=>'commission',
//looking for a solution something like this
        'dataProvider'=> new CActiveDataProvider('Store',array('data'=>$commission)),
        'filter'=>$model,
        'columns'=>array( 
            'percent.commission_percent',
            'percent.date_from',
            'percent.date_to',
                ))); ?>
    <?php //I don't want this anymore...
    foreach($commission as $percent){
        echo $percent->com_percent;
        echo $percent->date_from;
        echo $percent->date_to;
    }
    ?>

您需要在模型存储中定义关系,即

'percent'=>array(self::HAS_ONE, 'PercentageModel', 'store_id'),
然后你就可以随心所欲地使用它了

    'dataProvider'=> new CActiveDataProvider('Store'),
    'filter'=>$model,
    'columns'=>array( 
        'percent.com_percent',
        'percent.date_from',
        'percent.date_to',
    ))); ?>

它已经被定义了,。。这就是问题所在。。这是一对多。。一个商店可以有多个费率您可以为PercentageModel创建CActiveDataProvider吗?我不认为还有其他解决办法。哦,那太糟糕了。谢谢
    'dataProvider'=> new CActiveDataProvider('Store'),
    'filter'=>$model,
    'columns'=>array( 
        'percent.com_percent',
        'percent.date_from',
        'percent.date_to',
    ))); ?>