htmlspecialchars() error in grid display - newbie

I’m new to Yii/PHP etc. I inherited a project and I’m trying to make some minor changes to it. I’m getting the following error: htmlspecialchars() expects parameter 1 to be string, object given. I’m using Eclipse 20110218-0911 on Windows XP with Apache 2.2.

The call that is triggering the problem is:

<?php $this->widget(‘ExCGridView’, array(

'id'=&gt;'lesson-grid',


'dataProvider'=&gt;&#036;model-&gt;search(),	


'columns'=&gt;array(


	'id',


	'name',


	'lessonType',


	'sequence',


	'lessonFile',


//	'gradeLevel',	


	array('class' =&gt; 'CLinkColumn',


		'label' =&gt; 'View',


		'urlExpression'=&gt;'Yii::app()-&gt;createUrl(&quot;lesson/view&quot;,array(&quot;id&quot;=&gt;&#036;data-&gt;id))'


		),


),

));

?>

The field that is triggering the problem is lessonType. This field references a foreign key in another table and I want the grid to display the corresponding text for the item. I haven’t changed the structure of this grid except to remove the gradelevel column which is also a foreign key.

This error message appears to be a rather generic error. Any thoughts? How would you recommend that I go about debugging this?


Here’s the stack:

Stack Trace

#0 + C:\Projects\BESP\BESP_yii\framework\web\helpers\CHtml.php(66): htmlspecialchars(LessonTypeBase, 3, "UTF-8")

#1 + C:\Projects\BESP\BESP_yii\framework\utils\CFormatter.php(125): CHtml::encode(LessonTypeBase)

#2 + C:\Projects\BESP\BESP_yii\framework\utils\CFormatter.php(102): CFormatter->formatText(LessonTypeBase)

#3 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\grid\CDataColumn.php(135): CFormatter->format(LessonTypeBase, "text")

#4 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\grid\CGridColumn.php(135): CDataColumn->renderDataCellContent(0, LessonSearch)

#5 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\grid\CGridView.php(501): CGridColumn->renderDataCell(0)

#6 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\grid\CGridView.php(474): CGridView->renderTableRow(0)

#7 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\grid\CGridView.php(386): CGridView->renderTableBody()

#8 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\CBaseListView.php(158): CGridView->renderItems()

#9 unknown(0): CBaseListView->renderSection(array("{items}", "items"))

#10 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\CBaseListView.php(141): preg_replace_callback("/{(\w+)}/", array(ExCGridView, "renderSection"), "{summary} {items} {pager}")

#11 + C:\Projects\BESP\BESP_yii\framework\zii\widgets\CBaseListView.php(126): CBaseListView->renderContent()

#12 + C:\Projects\BESP\BESP_yii\framework\web\CBaseController.php(166): CBaseListView->run()

#13 – C:\Projects\BESP\webapp\protected\views\lesson\index.php(47): CBaseController->widget("ExCGridView", array("id" => "lesson-grid", "dataProvider" => CActiveDataProvider, "columns" => array("id", "name", "lessonType", "sequence", …)))

42 array(‘class’ => ‘CLinkColumn’,

43 ‘label’ => ‘View’,

44 ‘urlExpression’=>‘Yii::app()->createUrl(“lesson/view”,array(“id”=>$data->id))’

45 ),

46 ),

47 ));

48 ?>

#14 + C:\Projects\BESP\BESP_yii\framework\web\CBaseController.php(119): require("C:\Projects\BESP\webapp\protected\views\lesson\index.php")

#15 + C:\Projects\BESP\BESP_yii\framework\web\CBaseController.php(88): CBaseController->renderInternal("C:\Projects\BESP\webapp\protected\views/lesson\index.php", array("model" => LessonSearch), true)

#16 + C:\Projects\BESP\BESP_yii\framework\web\CController.php(866): CBaseController->renderFile("C:\Projects\BESP\webapp\protected\views/lesson\index.php", array("model" => LessonSearch), true)

#17 + C:\Projects\BESP\BESP_yii\framework\web\CController.php(779): CController->renderPartial("index", array("model" => LessonSearch), true)

#18 – C:\Projects\BESP\webapp\protected\controllers\LessonController.php(132): CController->render("index", array("model" => LessonSearch))

127 if(isset($_GET[‘LessonSearch’]))

128 $model->attributes=$_GET[‘LessonSearch’];

129

130 $this->render(‘index’,array(

131 ‘model’=>$model,

132 ));

133 }

134

135 public function actionValidateFiles()

136 {

137 $lessons = Lesson::model()->whereLessonTypeId(LESSONTYPE_COMPUTER)

#19 + C:\Projects\BESP\BESP_yii\framework\web\actions\CInlineAction.php(50): LessonController->actionIndex()

Is it possible that lessonType is also the name of a relation your model has? If so, gridview will load the relation object, but gridview will think it is a string.

Have your read this?

http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview

I know you don’t want to search (yet), but either way, this is going to helpful. Also make sure to read about relations, and relational active record.