先上代码 错误肯定就在这两个里边 但是不知道怎么解决 附网址:http://182.61.37.188/?r=login/entry
LoginController
load(Yii::$app->request->post())) {
print_r($model);
print_r(Yii::$app->request->post('userName'));
$info = new Userdb();
$info->userName = $model->username;
$info->password = $model->password;
$info->save();
return $this->render('showinfo', ['model' => $model]);
}else{
return $this->render('entry',['model' => $model]);
}
}
}
2.entry.php
'login-form',
'options' => ['class' => 'form-horizontal'],
'fieldConfig' => [
'template' => "{label}\n{input}
\n{error}
",
'labelOptions' => ['class' => 'col-lg-1 control-label'],
],
]); ?>
= $form->field($model, 'username')->textInput(['autofocus' => true]) ?>
= $form->field($model, 'password')->passwordInput() ?>
= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
做个调试看看,你先别用框架自带的
Yii::$app->request->post()获取,直接在控制器方法程序入口var_dump($_POST)看看有没有值通过$model->load(Yii::$app->request->post())就已经获取到了EntryForm的实例$model;打印$model->username试试
你可以尝试这种方法: