Can anyone, please help me on error "Array to String Conversion" in Yii.
Am getting this error "Array to String Conversion" for following code
Here is my code for create :
<div class="row">
<?php echo $form->labelEx($model,'emp_reporting'); ?>
<?php
$query="select 0 as emp_id,'ALL' as emp_name UNION select emp_id,emp_name from employee_master";
$result=Yii::app()->db->createCommand($query)->queryAll();
$ld=CHtml::listData($result,'emp_id','emp_name');
$x = array();
if(!$model->isNewRecord )
{
if( $model->emp_reporting != "") {
$query="select emp_id,emp_name from employee_master where emp_id in ($model->emp_reporting)";
$result=Yii::app()->db->createCommand($query)->queryAll();
$selected_list=CHtml::listData($result,'emp_id','emp_name');
foreach ($selected_list as $key => $value)
{
$x[$key]=array("selected"=>"selected");
}
}
}
$this->widget('ext.select2.ESelect2',array(
'model'=>$model,
'attribute'=>'emp_reporting',
'data'=>$ld,
'options'=>array(
'placeholder'=>'Select Employee ..',
),
'htmlOptions'=>array(
'multiple'=>'multiple',
'style'=>'width:200px;',
'options'=>$x,
),
));
?>
<?php echo $form->error($model,'emp_reporting'); ?>
</div>
This error exist when we try to use array
as string
but without knowing $result
, I can't say more but the syntax of listData
is like below
public static array listData(array $models, mixed $valueField, mixed $textField, mixed $groupField='')
So according to this $result
should be an array of model objects. Try to print $result
just above your listdata
and see what value it has
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.