【问题标题】:Form Not working in YII2表格在 YII2 中不起作用
【发布时间】:2015-06-17 08:40:56
【问题描述】:

我是 yii 框架的新手。

我已经创建了一个这样的。当我尝试像这样http://localhost/basic/web/index.php?r=site/user 在浏览器中查看表单时,我看到一个空白页。

我检查了 apache 日志,没有记录错误。

我已将文件添加到 git hub..https://github.com/sathyabaman/yii_basic_learning

型号

    <?php

    namespace app\models;
    use Yii;
    use yii\base\Model;


    class UserForm extends Model
    {
        public $name;
        public $email;



        public function rules()
        {
            return [

                [['name', 'email'], 'required'],

                ['email', 'email'],

            ];
        }

    }

控制器

 public function actionUser(){

    $model = new UserForm;



    if ($model->load(yii::$app->request->post()) && $model->validate()) {
        echo "string";
        # code...
    }else{
        $this->render('userForm', ['model'=> $model]);
    }
}

观看次数/网站

    <?php

    use yii\helpers\Html;
    use yii\widgets\ActiveForm;

    ?>

    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model, 'name'); ?>
    <?= $form->field($model, 'email'); ?>

    <?= Html::submitButton('submit', ['class'=>'btn btn-success']); ?>

    <?php $form = ActiveForm::end(); ?>

谁能帮我解决这个问题。 Tnx。

【问题讨论】:

  • 将错误报告设置为 E_ALL,并确保 display_errors 已打开。
  • 您确实有&lt;?php $form = ActiveForm::end(); ?&gt; 不是吗?
  • 不,我刚刚添加了那个。但没有变化仍然看到一个空白的白页
  • 请将error_reporting(-1); ini_set('display_errors', true); 放入您的index.php 中,看看是否能恢复您的输出。看看here

标签: php yii2


【解决方案1】:

在渲染前添加return

 return $this->render('userForm', ['model'=> $model]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多