Yii Framework Forum: Tbgridview And Render Customized/complex Datacolumns - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Tbgridview And Render Customized/complex Datacolumns Rate Topic: -----

#1 User is offline   AussieNeil 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 25-January 13

Posted 29 March 2013 - 11:05 PM

Hi All,

I am getting the following error:

htmlspecialchars() expects parameter 1 to be string, array given

when trying to do customized/complex datacolumns.

I have the following code:

<?php $this->widget('ext.bootstrap.widgets.TbGridView', array(
    'id'=>'rabbitshow-grid',
    'type'=>'striped bordered condensed',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'template'=>"{items}",
    'columns'=>array(
        array('name'=>'show_name', 'header'=>'Show'),
        array('name'=>'show_date', 'header'=>'Date'),
        array('name'=>'judge', 'header'=>'Judge'),
        array('name'=>'StatusText', 'header'=>'Status'),
        array(
            'name'=>'entries',
            'type'=>'raw', //because of using html-code from the rendered view
            //call the method 'gridMemberColumn' from the controller
            'value'=>array($this,'gridEntryColumn'),
        ),
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>


with gridEntryColumn defined as:

    protected function gridEntryColumn($data,$row)
    {
       $sql = 'SELECT entry_id, name, stud_name, member FROM lag_entry WHERE show_id = ' . $data->show_id .' ORDER BY name';
       $rows = Yii::app()->db->createCommand($sql)->queryAll();

       $result = '1';
       $idx = 1;
       if(empty($rows))
           foreach ($rows as $row)
           {
               $url = Yii::app()->createUrl('entry/view',array('entry_id'=>$row['entry_id']));
               $style = $idx % 2 == 0 ? 'background:#F8F8F8; padding:0.5em;' : 'background:#E5F1F4; padding:0.5em;';
               $text = CHtml::tag('div',array('style'=>$style),$row['name'].' '.$row['stud_name']);
               $result .= CHtml::link($text,$url) .'<br/>';
               $idx++;
           }
       return $result;
    }


now if I replace the TbGridZView with a CGridView it works correctly but I prefer a TbGridView. It appears more to be something to do with searching but I am not positive.

This is part of the stack trace:

Stack Trace
#0 	
+
 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(85): htmlspecialchars(array(), 3, "UTF-8")
#1 	
+
 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(2216): CHtml::encode(array())
#2 	
+
 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(140): CHtml::renderAttributes(array("name" => "Rabbitshow[entries]", "type" => "text", "value" => array()))
#3 	
+
 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(1890): CHtml::tag("input", array("name" => "Rabbitshow[entries]", "type" => "text", "value" => array()))
#4 	
+
 C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(1217): CHtml::activeInputField("text", Rabbitshow, "entries", array("name" => "Rabbitshow[entries]"))
#5 	
+
 C:\xampp\htdocs\yii\framework\zii\widgets\grid\CDataColumn.php(98): CHtml::activeTextField(Rabbitshow, "entries", array("id" => false)) 


Any ideas?
0

#2 User is offline   mrk 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 33
  • Joined: 07-March 11

Posted 30 March 2013 - 11:57 AM

Change line:
'value'=>array($this,'gridEntryColumn'),


into something like this
'value'=>function($row){return $this->gridEntryColumn($model, $row)}

or

'value'=>"$this->gridEntryColumn($model, $row)"

0

#3 User is offline   AussieNeil 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 21
  • Joined: 25-January 13

Posted 30 March 2013 - 04:30 PM

Hi,

Thanks for that but neither worked and returned the same error.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users