当前位置:Gxlcms > PHP教程 > YII框架接收不到post参数?

YII框架接收不到post参数?

时间:2021-07-01 10:21:17 帮助过:5人阅读

先上代码 错误肯定就在这两个里边 但是不知道怎么解决 附网址: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'],
    ],
]); ?>

field($model, 'username')->textInput(['autofocus' => true]) ?>

field($model, 'password')->passwordInput() ?>

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

field($model, 'username')->textInput(['autofocus' => true]) ?>

field($model, 'password')->passwordInput() ?>

    
        
             '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(), '' );

人气教程排行