本文介紹了如何在yii2中制作下拉列表?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
如何使用 activeform
和模型在 yii2
中制作 dropdown
?既然yii2
中所有的方法都發生了變化,那么新的方法是怎么做的呢?
How to make a dropdown
in yii2
using an activeform
and a model? Since all the methods has changed in yii2
,how it is done in the new one?
推薦答案
就像
<?php
use yiihelpersArrayHelper;
use backendmodelsStandard;
?>
<?= Html::activeDropDownList($model, 's_id',
ArrayHelper::map(Standard::find()->all(), 's_id', 'name')) ?>
Yii2 中的 ArrayHelper 替換了 Yii 1.1 中的 CHtml 列表數據.[請從您的控制器加載數組數據]
ArrayHelper in Yii2 replaces the CHtml list data in Yii 1.1.[Please load array data from your controller]
編輯
從控制器加載數據.
控制器
$items = ArrayHelper::map(Standard::find()->all(), 's_id', 'name');
...
return $this->render('your_view',['model'=>$model, 'items'=>$items]);
在視圖中
<?= Html::activeDropDownList($model, 's_id',$items) ?>
這篇關于如何在yii2中制作下拉列表?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!