Paul's Programming Notes PostsRSSGithub

htmlspecialchars() expects parameter 1 - Yii (echmultiselect)

htmlspecialchars() expects parameter 1 to be string, array given C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(98)

The error only occurred when trying to apply the echmultiselect filter to the filter above the gridview.

Here’s what I did to fix:

  1. Went to the Yii framework folder and found the following file: yii\framework\web\helpers\CHtml.php

  2. Modifed line 98 from return htmlspecialchars($text,ENT_QUOTES,Yii::app()->charset); to: return htmlspecialchars(print_r($text, true),ENT_QUOTES,Yii::app()->charset);

Then you need to implement the echmultiselect extension in the view (my example shows adding it for site_status):

  1. Added this php code to the view: $data= CHtml::listData(MyModel::model()->findAll(), 'blahblahblah', 'blahblahblah'); (but it should probably be in the model)

  2. Made my ‘columns’ array look like this:

'columns'=>array(
    'id',
    'blah',
    'blahblah',
    array (
        'name'=>'blahblahblah',
        'filter'=> $this->widget('ext.EchMultiselect.EchMultiselect',
            array(
                'model' => $model,
                'dropDownAttribute' => 'blahblahblah',
                'data' => $data,
                'options' => array('buttonWidth' => 80, 'ajaxRefresh' => true),
            ),
            true // capture output; needed so the widget displays inside the grid
        ),
    ),
    array(
        'class'=>'bootstrap.widgets.TbButtonColumn',
    ),
),