yii2_study8_Customizing_signup_form

1.在数据库advanced_yii2的user表的id后新加2个字段first_name,last_name
2.对应修改advanced/frontend/models/SignupForm.php,添加
public first_name;
public
last_name;
return里面添加:
[‘first_name’, ‘required’,”message”=>’this is add by aha68.com!’],
[‘last_name’, ‘required’],
signupz函数里添加:
user->first_name =this->first_name;
user->last_name =this->last_name;
3.修改form视图 advanced/frontend/views/site/signup.php
field($model, ‘first_name’) ?>
field($model, ‘last_name’) ?>
4.访问: http://https://https://cfzy.site/yii/advanced/frontend/web/index.php?r=site%2Fsignup,注册个新用户玩玩

Yii2_study3_form

1.yii\basic\models\下新建一个UserForm.php
[code]
<?php
namespace app\models;
use yii\base\Model;
class UserForm extends Model
{
public name;
public
email;
public function rules()
{
return [
[[‘name’,’email’],’required’],
[’email’,’email’],
];
}
}
?>
[/code]

2.yii\basic\controllers\SiteController.php里面增加一个function
[code]
public function actionUser()
{
model= new UserForm;
if(
model->load(yii::app->request->post()) &&model->validate())
{
echo "<div class=’alert-success’>".Yii::app->session->setFlash(‘success’,’ok,it is right!’)."</div>";

}
// else
// {
returnthis ->render(‘userForm’,[‘model’=>model]);
// }
}
[/code]

3.yii\basic\views\site\下新建userForm.php
[code]
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>

<?php
if(yii::app->session->hasFlash(‘success’))
{
echo yii::app->session->getFlash(‘success’);
}
?>

<?phpform=ActiveForm::begin();?>
<?= form->field(model,’name’);?>
<?= form->field(model,’email’);?>
<?= Html::submitButton(‘Submit’,[‘class’=>’btn btn-success’])?>
[/code]