YII框架接收不到post参数?

先上代码 错误肯定就在这两个里边 但是不知道怎么解决 附网址:http://182.61.37.188/?r=login/entry

  1. LoginController

<?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]);
        }

    }
}

2.entry.php

<?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(); ?>
阅读 8.2k
3 个回答

做个调试看看,你先别用框架自带的Yii::$app->request->post()获取,直接在控制器方法程序入口var_dump($_POST)看看有没有值

通过$model->load(Yii::$app->request->post())就已经获取到了EntryForm的实例$model;打印$model->username试试

你可以尝试这种方法:

$model->load(Yii::$app->request->post(), '' );
推荐问题
宣传栏