2 Question About Whselect2 (From Yiiwhells's Extension)

Hi,

I have add “tags” in my blog but I have some issues trying to use the WhSelect2’s widget.

First problem (that I found a "partial solution"):

The TbHtml::listData returns an array(id => text, …).

In the table tag, the column tag_id begins by 1 and some rows has been deleted. I have something like this:


array(1=>'Linux',

   3=>'Windows',

   4=>''Apple)

But I can’t use this array with WhSelect2 (for tags’s attribute). It’s seem that the key must begin by 0 and be incremented by 1 each time, like that:


array(0=>'Linux',

   1=>'Windows',

   2=>''Apple)

So I had override ListData that returns only the text of 1 column. It’s work but it’s bad, every time (and for each tag) I must retrieve the id doing a sql request of the text.


public static function listDataTest($models,$textField)

    {

        $listData=array();

        $i = 0;

        foreach($models as $model)

        {

            $text=self::value($model,$textField);

            $listData[$i]=$text;

            $i++;

        }

        return $listData;

    }

Second problem (that’s the one that makes me create this topic!)

When I create a new article there is no problem, but when I try to update an existing article, tags are not preload in the widget, I can’t understand how to do this? Using the data’s attribute? but how?

I tried this:


<?php 

                $this->widget('yiiwheels.widgets.select2.WhSelect2', array(

                    'asDropDownList' => false,

                    'name' => 'TagsSelect',

                    'pluginOptions' => array(

                        'tags' => TbHtml::listDataTest(Tag::model()->findAll(), 'tag_lib'),

                        //'data' => 'abcd' ,

                        //'data' => array('abcd') ,

                        //'data' => array(1=>'abcd') ,

                        'placeholder' => 'Ajouter un tag',

                        'width' => '40%',

                        'tokenSeparators' => array(',', ' ')

                )));

            ?>

But none of this syntax working, any idea?