Let’s start with the code. The error must be in these two, but I don’t know how to solve it. Attached URL: http://182.61.37.188/?r=login/entry
LoginController
<code><?php /** * Created by PhpStorm. * User: xin * Date: 16/6/29 * Time: 上午9:28 */ namespace app\controllers; use Yii; use yii\base\Controller; use app\models\Userdb; use app\models\EntryForm; class LoginController extends Controller{ public function actionEntry(){ $model = new EntryForm; if ($model->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]); } } }</code>
2.entry.php
<code><?php /** * Created by PhpStorm. * User: xin * Date: 16/6/29 * Time: 上午9:37 */ use yii\helpers\Html; use yii\widgets\ActiveForm; ?> <?php $form = ActiveForm::begin([ 'id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?></code>
Let’s start with the code. The error must be in these two, but I don’t know how to solve it. Attached URL: http://182.61.37.188/?r=login/entry
LoginController
<code><?php /** * Created by PhpStorm. * User: xin * Date: 16/6/29 * Time: 上午9:28 */ namespace app\controllers; use Yii; use yii\base\Controller; use app\models\Userdb; use app\models\EntryForm; class LoginController extends Controller{ public function actionEntry(){ $model = new EntryForm; if ($model->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]); } } }</code>
2.entry.php
<code><?php /** * Created by PhpStorm. * User: xin * Date: 16/6/29 * Time: 上午9:37 */ use yii\helpers\Html; use yii\widgets\ActiveForm; ?> <?php $form = ActiveForm::begin([ 'id' => 'login-form', 'options' => ['class' => 'form-horizontal'], 'fieldConfig' => [ 'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 'labelOptions' => ['class' => 'col-lg-1 control-label'], ], ]); ?> <?= $form->field($model, 'username')->textInput(['autofocus' => true]) ?> <?= $form->field($model, 'password')->passwordInput() ?> <div class="form-group"> <div class="col-lg-offset-1 col-lg-11"> <?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> </div> </div> <?php ActiveForm::end(); ?></code>
Let’s do some debugging. Don’t use the framework’s own Yii::$app->request->post()
to get it. Directly enter the controller method program entry var_dump($_POST)
to see if there is a value
You have obtained the EntryForm instance $model through $model->load(Yii::$app->request->post()); try printing $model->username
You can try this method:
<code>$model->load(Yii::$app->request->post(), '' );</code>