Is It Possible To Use Cgridview With Many-Many

Im trying to use cgridview and many-to-many .Is it possible?


foreach ($model->precos as $key => $value) {

    foreach ($value as $nome => $valor) {

        echo $nome . "<br>" . $valor . "---" . $nome;

    }

}

echo count($model->precos);

//CVarDumper::dump($model->precos);

$this->widget('zii.widgets.grid.CGridView', array(

    'id' => 'preco-grid',

    'dataProvider' => $model->search(),

    //'filter' => $model,

    'columns' => array(

        array(// this is for your related group members of the current group

            'name' => 'precos.zona_id', // this will access the attributeLabel from the member model class, and assign it to your column header

            'value' => '$data->precos->zona_id', // this will access the current group's 1st member and give out the firstname of that member

            'type' => 'raw' // this tells that the value type is raw and no formatting is to be applied to it

        ),

        array(// this is for your related group members of the current group

            'name' => 'precos.tabuleiro_id', // this will access the attributeLabel from the member model class, and assign it to your column header

            'value' => '$data->precos->tabuleiro_id', // this will access the current group's 1st member and give out the firstname of that member

            'type' => 'raw' // this tells that the value type is raw and no formatting is to be applied to it

        ),

        array(// this is for your related group members of the current group

            'name' => 'precos.menor_igual_um', // this will access the attributeLabel from the member model class, and assign it to your column header

            'value' => '$data->precos->menor_igual_um', // this will access the current group's 1st member and give out the firstname of that member

            'type' => 'raw' // this tells that the value type is raw and no formatting is to be applied to it

        ),

        array(// this is for your related group members of the current group

            'name' => 'precos.entre_dois_cinco', // this will access the attributeLabel from the member model class, and assign it to your column header

            'value' => '$data->precos->entre_dois_cinco', // this will access the current group's 1st member and give out the firstname of that member

            'type' => 'raw' // this tells that the value type is raw and no formatting is to be applied to it

        ),

        array(// this is for your related group members of the current group

            'name' => 'precos.mais_de_cinco', // this will access the attributeLabel from the member model class, and assign it to your column header

            'value' => '$data->precos->mais_de_cinco', // this will access the current group's 1st member and give out the firstname of that member

            'type' => 'raw' // this tells that the value type is raw and no formatting is to be applied to it

        ),

//        'zona_id',

//        'tabuleiro_id',

//        'menor_igual_um',

//        'entre_dois_cinco',

//        'mais_de_cinco',

        /*

          'created_at',

          'updated_at',

          'id_produto',

         */

        array(

            'class' => 'CButtonColumn',

        ),

    ),

));

but no records in cgridview. Can anybody point me right direction. Thanks

Hi,

Just try to print the size of cactivedataprovoder. then proceed with cgridview.I think u r not executing proper query to fetch the details. Please check the query

Check out my extension RelatedSearchBehavior and its demo - I am sure that you’ll learn from it:

http://www.yiiframework.com/extension/relatedsearchbehavior/ .