简体   繁体   English

错误数组到字符串的转换 - 在 Yii 中

[英]Error Array to String Conversion - In Yii

Can anyone, please help me on error "Array to String Conversion" in Yii.任何人都可以帮助我解决 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当我们尝试使用array作为string但不知道$result时存在此错误,我不能说更多但listData的语法如下

public static array listData(array $models, mixed $valueField, mixed $textField, mixed $groupField='')

So according to this $result should be an array of model objects.所以根据这个$result应该是一个模型对象数组。 Try to print $result just above your listdata and see what value it has尝试在listdata上方打印$result并查看它的值

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM