SOLVED - Tokeninput prePopulate

I’m having a problem setting the prepopulate option TokenInput

Tutorial says:

prePopulate

Prepopulate the tokeninput with existing data. Set to an array of JSON objects, eg: [{id: 3, name: "test"}, {id: 5, name: "awesome"}] to pre-fill the input. default: null




<?php $result = array('id' => $business->id, 'name' => $business->name); ?>

        <div class="row">

    <?php $this->widget('ext.tokeninput.TokenInput', array(

        'model' => $model,

        'attribute' => 'name',

        'url' => array('account/find'),

        //'value' => 'Terminal 5',

        'options' => array(

            'allowCreation' => true,

            'preventDuplicates' => true,

            'theme' => 'facebook',

            'prePopulate' => CJSON::encode($result),

        )

    )); ?>



However it populates : undefined undefined undefined many times, probably for each character in the array.

solution to the problem, make sure you make it an array of objects:


<?php $result[] = array('id' => $business->id, 'name' => $business->name); ?>

    <?php $this->widget('ext.tokeninput.TokenInput', array(

        'model' => $model,

        'attribute' => 'name',

        'url' => array('account/find'),

        //'value' => 'Terminal 5',

        'options' => array(

            'allowCreation' => true,

            'preventDuplicates' => true,

            'theme' => 'facebook',

            'prePopulate' => $result,

?>