2

I am new to yii framework.

I have created a from like this. When i try to view the form in the browser like this http://localhost/basic/web/index.php?r=site/user i see a blank white page.

I checked the apache log, No errors logged.

I have added the files to git hub.. https://github.com/sathyabaman/yii_basic_learning

Model

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

            ];
        }

    }

Controller

 public function actionUser(){

    $model = new UserForm;



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

Views/Sites

    <?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(); ?>

Can some one help me to fix this problem. Tnx.

Sathya Baman
  • 3,424
  • 7
  • 44
  • 77
  • 1
    Set error reporting to E_ALL, and make sure `display_errors` is on. – Mave Jun 17 '15 at 08:44
  • You do have `` in your view don't you? – chris--- Jun 17 '15 at 09:28
  • nope i just added that one. but no change still see a blank white page – Sathya Baman Jun 17 '15 at 09:32
  • Please put `error_reporting(-1); ini_set('display_errors', true);` in your `index.php` and see if you get your output back. Take a look [here](http://stackoverflow.com/questions/25139197/yii-white-screen-of-death-debugging-tips) – chris--- Jun 17 '15 at 09:57

2 Answers2

2

Add a return before render!

 return $this->render('userForm', ['model'=> $model]);
Dency G B
  • 8,096
  • 9
  • 47
  • 78
0

My code was different from this, but the outcome was kind-of the same, I could not load the model from the form. My mistake was I did not have rules for fields in the model - at least "safe" is required to load them - I keep forgetting this. Maybe, this'll help someone else in the future as well. E.g.:

public function rules()
{
    return [
        [['detailed', 'city', 'country'], 'string'],
    ];
}
András
  • 135
  • 1
  • 11