簡體   English   中英

嘗試使用數據庫中的值獲取下拉菜單,但將數組轉換為字符串錯誤(YII2)

[英]Trying to get dropdown menu with values from database but getting array to string conversion error (YII2)

這是我的代碼:

<?= 
    $rates= ApplicantRating::find()->all();     
    $listData= \yii\helpers\ArrayHelper::map($rates,'id','name'); 
    
    echo $form->field($model,'name')->dropDownList($listData,['prompt'=>'Select...']);
?>

我有一個:

PHP 注意 – yii\base\ErrorException 數組到字符串轉換錯誤

我不明白為什么。 它突出顯示$rates= ApplicantRating::find()->all(); 作為問題。 有什么建議嗎?

非常感謝。

您需要將<?=更改為<?php ,如下所示:

<?php 
    $rates= ApplicantRating::find()->all();     
    $listData= \yii\helpers\ArrayHelper::map($rates,'id','name'); 
    
    echo $form->field($model,'name')->dropDownList($listData,['prompt'=>'Select...']);
?>

<?= [sentence here]<?php echo [sentence here]相同 那么,php 試圖echo $rates會發生什么。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM