[英]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.