繁体   English   中英

PHP公告– yii \\ base \\ ErrorException(数组到字符串的转换)Yii

[英]PHP Notice – yii\base\ErrorException (Array to string conversion) Yii

我的数据成功输入数据库。 但是,插入后不能重定向到register.php页面。

显示通知,例如:

PHP公告 – yii \\ base \\ ErrorException

数组到字符串的转换

但是,我注意到,一旦我替换了这一行,就return $this->refresh($post); 从SiteController.php,一切正常。

所以,为什么这个refresh($post)不能正常工作..在其他页面上也可以正常工作。

我没有解决该问题的方法。 我需要帮助。 请帮我。

register.php

<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>

<?php $form = ActiveForm::begin(['id' => 'register-form']); ?>
    <?= $form->field($model, 'fname')->textInput()->label('First Name') ?>
    <?= $form->field($model, 'lname')->textInput()->label('Last Name') ?>
    <?= $form->field($model, 'email')->textInput()->label('Email') ?>
    <?= $form->field($model, 'password')->passwordInput()->label('Password') ?>
    <div class="form-group">
        <?= Html::submitButton('Register', ['class' => 'btn btn-success', 'name' => 'register-button' ]) ?>
    </div>
<?php ActiveForm::end(); ?>

SiteController.php(控制器)

<?php
namespace app\controllers;

use Yii;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\filters\VerbFilter;

class SiteController extends Controller
{
    public function actionRegister()
        {
        $model = new RegisterForm();
        if ($model->load(Yii::$app->request->post())) 
        {
            $post = Yii::$app->request->post('RegisterForm');

            Yii::$app->db->createCommand("INSERT INTO members SET FirstName=:fname, LastName=:lname, EmailID=:email, Password=:password",
                        array(':fname' => $post['fname'],':lname'=>$post['lname'],':email'=>$post['email'],':password'=>$post['password']))->execute();

            Yii::$app->session->setFlash('registerFormSubmitted');

            return $this->refresh($post);
        }
        return $this->render('register', [
            'model' => $model,
        ]);
        }
}

RegisterForm.php(模型)

<?php

namespace app\models;

use Yii;
use yii\base\Model;


class RegisterForm extends Model
{
    public $fname;
    public $lname;
    public $email;
    public $password;


    public function rules()
    {
        return [
            [['fname','lname', 'email', 'password'], 'required'],
            ['email', 'email'],
        ];
    }


    public function register()
    {
        if ($this->validate()) 
    {
        /*
                $form= new Form();
        $form->name=$this->name;
        $form->email=$this->email;
        $form->passowrd=$this->passowrd;
        $form->save();
        */
            return true;
        }
        return false;
    }

}

这是出现错误的打印屏幕。 在此处输入图片说明

您可以很容易地在错误屏幕上看到,向我们展示了发送到名为refresh()的方法的$anchor是一个数组,并且您试图将其串联起来,就好像它是一个字符串一样。 这就对了。

由于该屏幕上的文档说$anchor应该是该方法中的字符串,因此剩下的唯一原因是您向其发送了错误的数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM