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']) ?>

相关文章:

  • 2022-12-23
  • 2022-01-07
  • 2021-10-01
  • 2021-11-03
  • 2021-12-12
  • 2021-06-26
  • 2021-07-01
猜你喜欢
  • 2022-01-03
  • 2021-12-24
相关资源
相似解决方案