欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

YII框架接收不到post参数?

程序员文章站 2022-06-06 18:17:29
...
先上代码 错误肯定就在这两个里边 但是不知道怎么解决 附网址:http://182.61.37.188/?r=login/entry
  1. 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']) ?>

回复内容:

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

  1. 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']) ?>

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

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

你可以尝试这种方法:

$model->load(Yii::$app->request->post(), '' );
相关标签: php yii2