其他分享
首页 > 其他分享> > yii2 下拉菜单

yii2 下拉菜单

作者:互联网

model

public static function getCatlist(){
$cat = ['0' => '暂无分类'];
$res = self::find()->asArray()->all();
//print_r($res);die;
if($res){
foreach ($res as $k => $list) {
$cat[$list['id']] = $list['catname'];
}
// print_r($cat);die;
}
return $cat;
}

 

contoller

$cats = Catmodel::getCatlist();
//print_r($cats);die;
return $this->render('index', [
'model' => $model,
'cats' => $cats,
]);

 

view

<?=Html::activeDropDownList($model,'selects',$cats,['class'=>'form-control'])?>

<?=Html::submitButton('提交', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>
<?=Html::resetButton('重置', ['class'=>'btn btn-primary','name' =>'submit-button']) ?>

标签:btn,res,cat,cats,die,print,yii2,下拉菜单
来源: https://blog.51cto.com/u_13481146/2819324