2

Here is my controller:

class RoomController extends Controller
{
public function actionCreate()
{
$model = new Room();
$modelSave = false;
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
}
return $this->render('create', ['model' => $model,'modelSaved' => $modelSave]);
}
}

and here is my view

<?php if($modelSave) { ?>
<div class = "alert alert-success" >
Model ready to be saved!
</div>
<?php } ?>
<?php $form = ActiveForm::begin(); ?>
<div class="row">
<div class = "col-lg-12">
<h1>Room Form</h1>
<?= $form->field($model,'floor')->textinput()?>
<?= $form->field($model,'room_number')->textinput() ?>
<?= $form->field($model,'has_conditioner')->checkbox() ?>
<?= $form->field($model,'has_tv')->checkbox() ?>
<?= $form->field($model,'has_phone')->checkbox() ?>
<?= $form->field($model,'available_form')->textinput() ?>
<?= $form->field($model,'price_per_day')->textinput() ?>
<?= $form->field($model,'description')->textarea() ?>
</div>
</div>
<div class="form-group">
<?= Html::submitButton('create',['class'=>'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>

when i checked whether if it working, the ErrorException shows:

PHP Notice – yii\base\ErrorException Undefined variable: modelSave

I've tried to debug, but I have no idea why the $modelSave can't send to the view "create".

1
  • I don't know YII, but try $this->modelSave, $this->modelSaved, $modelSaved. Commented Dec 21, 2015 at 13:58

2 Answers 2

4

You test

<?php if($modelSave) { ?>

but in your render you have

return $this->render('create', ['model' => $model,'modelSaved' => $modelSave]);

use

<?php if($modelSaved) { ?>
Sign up to request clarification or add additional context in comments.

Comments

3

You don't call the variable by its name, you should try to check $modelSaved since this is the name you give it

replace

<?php if($modelSave) { ?>

by

<?php if($modelSaved) { ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.