Skip to content

Getting All Tags for each model in CGridView #25

Description

@larry-tx

I would like to have a CGridView column that displays all tags for each model listed in the index (list) and admin views. I've tried some thing like this in CGridView:

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'              => 'disks-grid',
    'dataProvider'    => $model->search(),
    'filter'          => $model,
    'columns'         => array(
      // additional column definitions
        array(
            'name'   => 'tags_with_model',
            'header' => 'Tags',
            'type'   => 'raw',
            'filter' => FALSE,
            'value'  => $model->tags_with_model->toString(),
        ),
        // ,,,

Unfortunately, that produces nothing. No errors, just a totally blank column. (Interestingly, I was able to use tags_with_model->toString(); ?> to display the tags in view.php, and it worked quite nicely.) Apparently, something happens in CGridView to prevent toString() from working.

By the way, my behavior in the model looks like:

public function behaviors() {
            return array(
                'tags_with_model' => array(
                    'class'                   => 'ext.yiiext.behaviors.model.taggable.ETaggableBehavior',
                    'tagTable'                => 'tag',
                    'tagBindingTable'         => 'disks_tag',
                    'modelTableFk'            => 'disksId',
                    'tagTablePk'              => 'id',
                    'tagTableCount'           => 'frequency',
                    'tagBindingTableTagId'    => 'tagId',
                    'createTagsAutomatically' => TRUE,
                ),
            );
        }

Can anyone tell me how to get a column in CGridView that displays the tags for each model?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions