标签:cto 组件 save use view style input dir form
文本框:textInput();
密码框:passwordInput();
单选框:radio(),radioList();
复选框:checkbox(),checkboxList();
下拉框:dropDownList();
隐藏域:hiddenInput();
文本域:textarea([‘rows‘=>3]);
文件上传:fileInput();
提交按钮:submitButton();
重置按钮:resetButtun();
<?php $form = ActiveForm::begin([‘action‘ => [‘test/getpost‘],‘method‘=>‘post‘,]); ?> //提交的控制器
<?= $form->field($model, ‘username‘)->textInput([‘maxlength‘ => 20])->label(‘起的名字‘) ?>
<?= $form->field($model, ‘password‘)->passwordInput([‘maxlength‘ => 20])->label(‘起的名字‘)
?>
<?= $form->field($model, ‘sex‘)->radioList([‘1‘=>‘男‘,‘0‘=>‘女‘])->label(‘起的名字‘)
?>
<?= $form->field($model, ‘edu‘)->dropDownList([‘1‘=>‘大学‘,‘2‘=>‘高中‘,‘3‘=>‘初中‘], [‘prompt‘=>‘请选择‘,‘style‘=>‘width:120px‘])->label(‘起的名字‘)
?>
<?= $form->field($model, ‘file‘)->fileInput()->label(‘起的名字‘)
?>
<?= $form->field($model, ‘hobby[]‘)->checkboxList([‘0‘=>‘篮球‘,‘1‘=>‘足球‘,‘2‘=>‘羽毛球‘,‘3‘=>‘乒乓球‘])->label(‘起的名字‘)
?>
<?= $form->field($model, ‘info‘)->textarea([‘rows‘=>3])->label(‘起的名字‘)
?>
<?= $form->field($model, ‘userid‘)->hiddenInput([‘value‘=>3])->label(‘起的名字‘)
?>
<?= Html::submitButton(‘提交‘, [‘class‘=>‘btn btn-primary‘,‘name‘ =>‘submit-button‘]) ?>
<?= Html::resetButton(‘重置‘, [‘class‘=>‘btn btn-primary‘,‘name‘ =>‘submit-button‘]) ?>
<?php ActiveForm::end(); ?>
控制器里
接值
/**
* Creates a new User model.
* If creation is successful, the browser will be redirected to the ‘view‘ page.
* @return mixed
*/
public function actionCreate()
{
$model = new User(); //实例化model
if ($model->load(Yii::$app->request->post())) {
$re=\Yii::$app->request->post();
$sex=implode(‘,‘,$re[‘User‘][‘sex‘]);//把数组转换字符串
$re[‘User‘][‘sex‘]=$sex;//重新赋值数组
$model->name=$re[‘User‘][‘name‘];
$model->pwd=$re[‘User‘][‘pwd‘];
$model->sex=$re[‘User‘][‘sex‘];
$model->save();//入库保存
return $this->redirect([‘view‘, ‘id‘ => $model->id]);
} else {
return $this->render(‘create‘, [
‘model‘ => $model,
]);
}
}
yii2.0 Activeform表单部分组件使用方法 [ 2.0 版本 ]
标签:cto 组件 save use view style input dir form
原文地址:http://www.cnblogs.com/wangzhilei/p/6532680.html