Home > Backend Development > PHP Tutorial > YII framework cannot receive post parameters?

YII framework cannot receive post parameters?

WBOY
Release: 2016-07-06 13:51:53
Original
2298 people have browsed it

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

  1. 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

Reply content:

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

  1. 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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template